[英]PHP Get keys from one array of intersected values
in php, if I have two arrays: 在PHP中,如果我有两个数组:
array1 = array('a', 'b', 'c');
array2 = array('b', 'c');
Is there a function of combination of functions that will compare the two arrays' values and return the keys from 1 array of the intersection? 是否存在函数组合的功能,它将比较两个数组的值并从交集的1个数组返回键?
If wanting the key
s from array1
, they would be 1
and 2
If wanting the key
s from array2
, they would be 0
and 1
如果想要来自
array1
的key
,它们将是1
和2
如果想要来自array2
的key
,它们将是0
和1
Compare: 相比:
$rgResult = array_keys(array_intersect($array1, $array2));
and 和
$rgResult = array_keys(array_intersect($array2, $array1));
你正在寻找array_intersect
array_keys(array_intersect($array1, $array2));
array_keys($array1 = array('a', 'b', 'c'); $array2 = array('b', 'c');
$intersection = array_intersect($array1, $array2);
$keys = array();
foreach($intersection as $i){
$keys[]= array_search($i,$array1);
}
print_r($keys);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.