Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save synsa/50b1c9de661f891b838204b0252fcaef to your computer and use it in GitHub Desktop.
Save synsa/50b1c9de661f891b838204b0252fcaef 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