且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP处理多维数组值

更新时间:2023-02-23 09:37:48

使用 array_walk_recursive :

如果您的PHP> = 5.3.0(用于匿名函数):

If you have PHP >= 5.3.0 (for anonymous functions):

array_walk_recursive($result, function (&$item, $key) {
    if ($key == 'b') {
        $item = 'the key is b!';
    }
});

否则类似:

function _my_method(&$item, $key) {
    if ($key == 'b') {
        $item = 'the key is b!';
    }
}
array_walk_recursive($result, '_my_method');