function array_walk_recursive_array(array &$array, callable $callback) {
foreach ($array as $k => &$v) {
if (is_array($v)) {
array_walk_recursive_array($v, $callback);
} else {
$callback($v, $k, $array);
}
}
}
$array = [
['foo'],
['bar'],
'baz'
];
$array = [
[
'foo',
'a' => 'b'
],
[
'bar',
'a' => 'b'
],
'baz'
];
array_walk_recursive_array( $array, function( $v, $k, $array ) {
if ( is_array( $v ) ) {
$v = $v['a'] = 'b';
return $v;
}
else return $v;
});
if (is_array($v)) {
array_walk_recursive_array($v, $callback);
function array_walk_recursive_array(array &$array, callable $callback) {
foreach ($array as $k => &$v) {
// if (is_array($v)) {
// array_walk_recursive_array($v, $callback);
// } else {
$callback(& $v, $k, $array);
// }
}
}
array_walk_recursive_array( $array, function( $v, $k, $array ) {
if ( is_array( $v ) ) {
$v = $v['a'] = 'b';
return $v;
}
else return $v;
});
$array = [
['foo'],
['bar'],
'baz'
];
$array = [
[
'foo',
'a' => 'b'
],
[
'bar',
'a' => 'b'
],
'baz'
];
<?php
echo "Что есть:\r\n";
$array = [
['foo'],
['bar'],
'baz'
];
var_dump($arr);
echo "----------------------------------------------\r\n";
echo "Что хотим получить:\r\n";
var_dump([
[
'foo',
'a' => 'b'
],
[
'bar',
'a' => 'b'
],
'baz'
]);
echo "----------------------------------------------\r\n";
echo "Процесс:\r\n";
$add_array = [
'a' => 'b'
];
foreach ($array as $key => $value){
if(is_array($value)){
$array[$key] += $add_array;
}
}
echo "----------------------------------------------\r\n";
echo "Полученный результат:\r\n";
var_dump($array);
foreach