我有两个数组
1.$ids;
Array
(
[0] => 2427975642
[1] => 2397521678
)
2.$c
Array
(
[48] => 2397521678
[46] => 461
[45] => 451
)
问题:在 $c 中从 $ids 中搜索值并返回带有 id 的新数组。示例返回 48
查看函数array_intersect:http://php.net/manual/en/function.array-intersect.php
$ids = array(
2427975642,
2397521678
);
$c = array(
48 => 2397521678,
46 => 461,
45 => 451
);
$common = array_keys(array_intersect($c, $ids));
print_r($common);
$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);
$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;
}
}