Skip to content

Instantly share code, notes, and snippets.

@igorw
Created November 24, 2013 14:48
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igorw/7628042 to your computer and use it in GitHub Desktop.
Save igorw/7628042 to your computer and use it in GitHub Desktop.
<?php
function array_map_recursive($f, $xs) {
$out = [];
foreach ($xs as $k => $x) {
$out[$k] = (is_array($x)) ? array_map_recursive($f, $x) : $f($x);
}
return $out;
}
$data = [
'foo' => [
'bar' => [
'baz' => [
'rofl',
'omg',
'wtf',
],
],
],
];
var_dump(array_map_recursive('strtoupper', $data));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment