Skip to content

Instantly share code, notes, and snippets.

@opengeek
Created August 4, 2015 03:23
Show Gist options
  • Save opengeek/40fd4e270c3374cd8592 to your computer and use it in GitHub Desktop.
Save opengeek/40fd4e270c3374cd8592 to your computer and use it in GitHub Desktop.
Implode an associative array using `array_walk()`
<?php
$array = array(
'key1' => 'value1',
'key2' => 'value2',
'key3' => 'value3',
);
$flattened = $array;
array_walk($flattened, function(&$value, $key) {
$value = "{$key} ({$value})";
});
echo 'The values are ' . implode(', ', $flattened);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment