Created
August 4, 2015 03:23
-
-
Save opengeek/40fd4e270c3374cd8592 to your computer and use it in GitHub Desktop.
Implode an associative array using `array_walk()`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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