如何找到两个数组的差异
// ARRAY 1
$a1 = array(
"a1" => 1,
"a3" => array(
"a31" => 31
),
"a4" => array(
"a41" => 41
),
"a5" => array(
"a51" => 51,
"a52" => 52
)
);
// ARRAY 2
$a2 = array(
"a1" => 1,
"a2" => 2,
"a3" => array(
"a31" => 31,
"a32" => array(
"a321" => 321,
"a322" => 322
)
),
"a4" => array(
"a41" => 42
),
"a5" => array(
"a51" => 51,
"a52" => 52
)
);
array_diff函数返回==> Array ( )
但上述两个数组变量存在很多差异。
示例:
所以这里我要比较两个数组n级(即嵌套数组)
答案 0 :(得分:1)
$results = array_diff(array_map('serialize',$a2),array_map('serialize',$a1));
$results = array_map('unserialize',$results);
echo '<pre>';
print_r($results);