Forked from opengeek/implodeAssociativeArrayWithArrayWalk.php
Created
September 16, 2022 06:18
-
-
Save synsa/50b1c9de661f891b838204b0252fcaef 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