我试图从多维数组中删除所有元素等于另一个多维数组。
例如,我是这两个数组;
$array1 = Array ( [0] => Array ( [item1] => 3017, [item2] => 7 ), [1] => Array ( [item1] => 3018, [item2] => 4 ), [2] => Array ( [item1] => 3020, [item2] => 9 ), [3] => Array ( [item1] => 3024, [item2] => 5 ) )
和
$array2 = Array ( [0] => Array ( [item1] => 3017, [item2] => 7 ), [1] => Array ( [item1] => 3018, [item2] => 200 ), [2] => Array ( [item1] => 3020, [item2] => 300 ), [3] => Array ( [item1] => 3024, [item2] => 5 ) )
这两个数组之间的差异是元素[1]和[2]中[item2]的值。
我想得到一个只包含第一个数组的不同值的数组。就我而言,应该是:
array_diff = array( [1] => Array ( [item1] => 3018, [item2] => 4 ), [2] => Array ( [item1] => 3020, [item2] => 9 ) )
答案 0 :(得分:0)
使用json比较;)
$jsonDiff = array_diff(array_map('json_encode', $array1), array_map('json_encode', $array2));
$arrayDiff = array_map('json_decode', $diff);
问候。