我有两个数组
1 $ IDS;
Array
(
[0] => 2427975642
[1] => 2397521678
)
2 $ C
Array
(
[48] => 2397521678
[46] => 461
[45] => 451
)
问题: 从$ c中的$ ids中搜索值,并返回带有id的新数组。示例返回48
答案 0 :(得分:1)
查看函数array_intersect:http://php.net/manual/en/function.array-intersect.php
答案 1 :(得分:1)
$ids = array(
2427975642,
2397521678
);
$c = array(
48 => 2397521678,
46 => 461,
45 => 451
);
$common = array_keys(array_intersect($c, $ids));
print_r($common);
答案 2 :(得分:1)
$ids= array
(
[0] => 2427975642
[1] => 2397521678
);
$c =array
(
[48] => 2397521678
[46] => 461
[45] => 451
);
$res = array_intersect($ids,$c);
$keys = array_keys($res);
print_r($keys);
答案 3 :(得分:0)
$ids = array(
2427975642,
2397521678
);
$c = array(
48 => 2397521678,
46 => 461,
45 => 451
);
$finalArray = array();
foreach ( $c as $key=>$val)
{
if ( array_search($val,$ids))
{
$finalArray[]=$key;
}
}