1

我有两个数组$A$B

$B = Array
(
    [0] => Array
        (
            [id_participant] => 94
            [full_name] => soeng makara
        )

    [1] => Array
        (
            [id_participant] => 95
            [full_name] => sok sao
        )

)

$A = Array
(
    [0] => Array
        (
            [id_participant] => 95
            [full_name] => sok sao
        )
)

任何人都可以帮助我在这种情况下如何检查数组$A中的数组$B

4

2 回答 2

3

简单地:

if (in_array($A[0], $B))
{
  // in array
}
于 2012-07-23T23:52:06.427 回答
2

您想知道 $a 中的项目是否在 $b 中?

function checkIfInArray($a, $b)    
{
    foreach($b as $i)
        foreach($a as $x)
            if($x['id_participant'] == $i['id_participant']) return true; //Match found
    return false; //No Match was found
}
于 2012-07-23T22:39:31.210 回答