私は2つの配列を持っています
1.$ID;
Array
(
[0] => 2427975642
[1] => 2397521678
)
2.$c
Array
(
[48] => 2397521678
[46] => 461
[45] => 451
)
質問: $c の $ids から値を検索し、id を持つ新しい配列を返します。戻り値の例 48
$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
);
$common = array_keys(array_intersect($c, $ids));
print_r($common);
関数 array_intersect をチェックしてください: http://php.net/manual/en/function.array-intersect.php
$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;
}
}