我有这些数组:如何知道对关键的,从返回array_intersec
$a = ['a','b','c','d','e','f'];
$b = ['d','e','f'];
如果我使用array_intersect上面像阵列,
$c = array_intersect($a, $b);
$d = array_intersect($b,$a);
$ C将返回:
Array
(
[3] => d
[4] => e
[5] => f
)
and $ d will return:
Array
(
[0] => d
[1] => e
[2] => f
)
我怎样才能知道该对那些array_intersection等的关键的,
[3] --> [0]
[4] --> [1]
[5] --> [2]
我的意思,[3]数组$a
的[0]在阵列$b
相交具有索引的索引。我怎么知道?
非常感谢。
选择的答案是时间,因为耗时' array_search()': - https://eval.in/768069(检查时间)对我的答案链接(https://eval.in/768032)。实际上并不需要。如果阵列长度增加,将变得更加方便。 –
'foreach()'和'array_search()'?不是一个好的方法(谈论由OP选择的答案)。更费时: - https://eval.in/768069(检查时间)对我的答案链接(https://eval.in/768032)。不需要这样做。如果数组长度增加 –