php array_walk_recursive code example
Example 1: array_walk_recursive get return value
Flatten multidimensional associative array to array
function flatten(array $array, $prefix="") {
$result = Array();
array_walk($array, function ($value, $key) use ($array, $prefix, &$result) {
$path = $prefix ? "$prefix.$key" : $key;
if (is_array($value)) {
$result = array_merge($result, flatten($value, $path));
} else {
$result[$path] = $value;
}
});
return $result;
}
print_r(flatten($arrr));
from site:
https:
Example 2: php array_walk_recursive
$arr = array(1, array(2, 3));
array_walk_recursive($arr, function(&$item, $key, $myParam){
$item *= 2;
}, 'will be in myParam');