我有一个多维数组,可以根据用户输入增加。我想在数组内执行
array_intersect()
来获取键之间的公共值。
就像例子
Array (
[php] => Array ( [0] => 36 [1] => 51 [2] => 116 [3] => 171 [4] => 215 [5] => 219 [6] => 229 [7] => 247 [8] => 316 )
[java] => Array ( [0] => 14 [1] => 16 [2] => 19 [3] => 24 [4] => 25 [5] => 26 [6] => 29 [7] => 31 [8] => 33 [9] => 34 [10] => 35 [11] => 36 [12] => 37 [13] => 40 [14] => 45 [15] => 49 [16] => 51 )
)
预期输出应类似于 (36,51)
这就是我能够通过以下方式获得的:
$intersected_array = call_user_func_array('array_intersect', $array);
但是如果我的数组还有第三个键,而这三个键也没有共同的值
喜欢
Array (
[php] => Array ( [0] => 36 [1] => 51 [2] => 116 [3] => 171 [4] => 215 [5] => 219 [6] => 229 [7] => 247 [8] => 316 )
[java] => Array ( [0] => 14 [1] => 16 [2] => 19 [3] => 24 [4] => 25 [5] => 26 [6] => 29 [7] => 31 [8] => 33 [9] => 34 [10] => 35 [11] => 36 [12] => 37 [13] => 40 [14] => 45 [15] => 49 [16] => 51 )
[ajax] => Array ( [0] => 91 [1] => 110 [2] => 113 [3] => 172 )
)
然后它会将输出作为具有最大值的键的结果。在这种情况下,它将返回
java
键的所有值。
但我的预期输出是
0
。
我复制了你的例子,对我来说它有效:
<?php
$array = array(
'php' => array(
36,
51,
116,
171,
215,
219,
229,
247,
316,
),
'java' => array(
14,
16,
19,
24,
25,
26,
29,
31,
33,
34,
35,
36,
37,
40,
45,
49,
51,
),
'ajax' => array(
91,
110,
113,
172,
),
);
$intersected_array = call_user_func_array('array_intersect',$array);
print_r($intersected_array);
// RESULT: "Array ( ) "
请准确复制此代码并告诉我你的输出。