使用array_diff(),我可以比较和删除相似的项目,但是如果我有以下数组怎么办?
array_diff()
阵列1
Array ( [0] => Array ( [ITEM] => 1 ) [1] => Array ( [ITEM] => 2 ) [2] => Array ( [ITEM] => 3 ) )
数组2
Array ( [0] => Array ( [ITEM] => 2 ) [1] => Array ( [ITEM] => 3 ) [2] => Array ( [ITEM] => 1 ) [3] => Array ( [ITEM] => 4 ) )
我想过滤掉类似的物品;结果应该返回4.如何重新排列数组以便可以使用array_diff()?
我可能会遍历原始数组并使它们成为一维的…类似
foreach($array1 as $aV){ $aTmp1[] = $aV['ITEM']; } foreach($array2 as $aV){ $aTmp2[] = $aV['ITEM']; } $new_array = array_diff($aTmp1,$aTmp2);