1

我有两个数组

1.$ids;

Array
(
    [0] => 2427975642
    [1] => 2397521678
)

2.$c

Array
(
    [48] => 2397521678
    [46] => 461
    [45] => 451
)

问题:在 $c 中从 $ids 中搜索值并返回带有 id 的新数组。示例返回 48

4

4 回答 4

1

查看函数array_intersect:http://php.net/manual/en/function.array-intersect.php

于 2012-08-07T08:34:12.467 回答
1
$ids = array(   
    2427975642,
    2397521678
);



$c = array(
    48 => 2397521678,
    46 => 461,
    45 => 451
);

$common = array_keys(array_intersect($c, $ids));

print_r($common);
于 2012-08-07T08:37:29.863 回答
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);
于 2012-08-07T08:41:03.513 回答
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;

}

}
于 2012-08-07T08:39:04.917 回答