Reputation: 55
I have two arrays
1.$ids;
Array
(
[0] => 2427975642
[1] => 2397521678
)
2.$c
Array
(
[48] => 2397521678
[46] => 461
[45] => 451
)
Question: Search values from $ids in $c and return new array with id. Example return 48
Upvotes: 1
Views: 151
Reputation: 3065
$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);
Upvotes: 1
Reputation:
$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;
}
}
Upvotes: 0
Reputation: 2408
$ids = array(
2427975642,
2397521678
);
$c = array(
48 => 2397521678,
46 => 461,
45 => 451
);
$common = array_keys(array_intersect($c, $ids));
print_r($common);
Upvotes: 1
Reputation: 2711
Check out the function array_intersect: http://php.net/manual/en/function.array-intersect.php
Upvotes: 1