Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
查找所有子数组中存在的元素的php数组_Php - Fatal编程技术网

查找所有子数组中存在的元素的php数组

查找所有子数组中存在的元素的php数组,php,Php,我有一个包含一些值的php多维数组(2级),我想确定所有数组中都存在哪些值 Array ( [1] => Array ( [0] => 1 [1] => 3 ) [2] => Array ( [0] => 1 [1] => 2 ) [3] => Array

我有一个包含一些值的php多维数组(2级),我想确定所有数组中都存在哪些值

Array
(
    [1] => Array
        (
            [0] => 1
            [1] => 3
        )

    [2] => Array
        (
            [0] => 1
            [1] => 2
        )

    [3] => Array
        (
            [0] => 1
            [1] => 3
        )

)
..在我们的例子中,值1出现在所有二级数组中。有什么方法可以识别它吗?

您可以使用它对所有阵列进行交集:

$intersection = $arr[0];
for ($i=1, $n=count($arr); $i<$n; ++$i) {
    $intersection = array_intersect($intersection, $arr[$i]);
    if (empty($intersection)) break;
}
可以使用进行所有阵列的相交:

$intersection = $arr[0];
for ($i=1, $n=count($arr); $i<$n; ++$i) {
    $intersection = array_intersect($intersection, $arr[$i]);
    if (empty($intersection)) break;
}