Merge key and value of array index [duplicate]
PHP Snippet 1:
$arr = ['foo'=>'bar','baz'=>'bat'];
$combine = array_map(fn($k, $v) => "$k: $v", array_keys($arr), array_values($arr));
print_r($combine);
PHP Snippet 2:
Array
(
[0] => foo: bar
[1] => baz: bat
)
PHP Snippet 3:
$arr = [ 'foo' => 'bar', 'baz' => 'bat' ];
$result = [];
array_walk($arr, function ($value, $key) use (&$result) {
$result[] = "$key: $value";
});