php根据字段合并两个二维数组的实例代码

php根据字段合并两个数组,将b数组aid跟a中id 相同的合并到一起,用array_search,array_column进行二维数组搜索,搜索到的话合并,具体代码如下: $a = array( array("id"= "1","name"= "aaa","switch"= "on"), array("id"= "2","name"= "aaa","switch"= "on"), array("id"= "3","name"= "a

php根据字段合并两个数组,将b数组aid跟a中id 相同的合并到一起,用array_search,array_column进行二维数组搜索,搜索到的话合并,具体代码如下:
        $a = array(
            array("id"=> "1","name"=> "aaa","switch"=> "on"),
            array("id"=> "2","name"=> "aaa","switch"=> "on"),
            array("id"=> "3","name"=> "aaa","switch"=> "on"),
            array("id"=> "4","name"=> "aaa","switch"=> "on"),
 
        );
 //编程学习网整理
        $b = array(
            array("aid"=> "1","list"=> "0","add"=> 1),
            array("aid"=> "2","list"=> "1","add"=> 0),
            array("aid"=> "3","list"=> "0","add"=> 1),
 
        );
        $temp = array_column($a, 'id');
        foreach ($b as $k => $v){
            $index = array_search($v['aid'], $temp);
            $index && $a[$index] = array_merge($a[$index],$v);
 
        }
 

本文标题为:php根据字段合并两个二维数组的实例代码