比较数组中数组的相同值

时间:2017-01-21 05:02:43

标签: php arrays laravel

我有两个数组内容另一个数组。如何从中检查相同的值?

Array ( [0] => Array ( [0] => 36 [1] => 43 [2] => 47 [3] => 51 [4] => 52 [5] => 54 [6] => 56 ) [1] => Array ( [0] => 38 [1] => 44 [2] => 47 [3] => 50 [4] => 53 [5] => 55 [6] => 57 ) ) 

Array ( [0] => Array ( [0] => 37 [1] => 57 [2] => 54 [3] => 52 [4] => 51 [5] => 44 [6] => 47 ) [1] => Array ( [0] => 54 [1] => 57 [2] => 51 [3] => 53 [4] => 47 [5] => 43 [6] => 39 ) [2] => Array ( [0] => 55 [1] => 57 [2] => 53 [3] => 51 [4] => 48 [5] => 44 [6] => 38 ) [3] => Array ( [0] => 55 [1] => 53 [2] => 51 [3] => 47 [4] => 44 [5] => 37 [6] => 57 ) )

1 个答案:

答案 0 :(得分:0)

首先合并每个数组,使用+或array_merge作为索引,数字不是字符串。然后你可以使用array_intersect

$temp = [];
foreach($arr1 as $arr)
{
  $temp += $arr;
}
$array1 = $temp;

var_dump(array_intersect($array1, $array2));