Say I have an array of key/value pairs in PHP:
array( \'foo\' => \'bar\', \'baz\' => \'qux\' );
What\'s the simplest way to transform
Another option for this problem: On PHP 5.3+ you can use array_map()
with a closure (you can do this with PHP prior 5.2, but the code will get quite messy!).
"Oh, but on
array_map()
you only get the value!".
Yeah, that's right, but we can map more than one array! :)
$arr = array( 'foo' => 'bar', 'baz' => 'qux' );
$result = array_map(function($k, $v){
return "$k=$v";
}, array_keys($arr), array_values($arr));