我有一个包含一些值的数组,我需要检查某些值是否不在这个数组中。
这是第一个数组:
Array ( [0] => Array ( [0] => Paris SG [1] => Brest [2] => Monaco [3] => Nizza [4] => Lilla [5] => Lens ) [1] => Array ( [0] => Marsiglia [1] => Rennes [2] => Reims [3] => Lione [4] => Tolosa [5] => Strasburgo ) [2] => Array ( [0] => Le Havre [1] => Montpellier [2] => Lorient [3] => Nantes [4] => Metz [5] => Clermont ) )
第二个数组:
`Array ( [0] => Sturm Graz [1] => Rennes [2] => Sturm Graz [3] => Reims [4] => Tolosa [5] => Le Havre [6] => Paris SG [7] => Lione [8] => Clermont [9] => Montpellier [10] => Lorient [11] => Strasburgo ) `
我需要从第二个数组中删除第一个数组中不存在的值,在本例中为 value[0] 和 value[2] (Sturm Graz)。
我尝试了这个但不起作用。
`$part_t2_2=数组(); foreach($part_t2 作为 $value){
if (in_array($value,$arr_cls[0],true) or in_array($value,$arr_cls[1],true) or in_array($value,$arr_cls[2],true)){
$part_t2_2[]=$value;
}
}`
你是这个意思吗?
foreach($arra2 as $el2)
{
foreach($arra1 as $el1)
{
if($el2===$el1)
{
$array2[]=$el1;
}
}
}
var_dump($array2);