I have an array with some values and I need to check if some values are not in this array.
This is the first array with name "$arr_cls".
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 )
)
the second array: with name "$part_t2"
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 )
i need to remove from second array the value that not exist into first array in this case value[0] and value[2] (Sturm Graz).
i try this but not work.
$part_t2_2=array();
foreach($part_t2 as $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;
}
}
2
Answers
is that what you mean?
you can also use the count and for functions
One of the ways is to flatten the nested array first, then use in_array and a loop to do the job
We may use this function to flatten the nested array
then loop over it, use in_array to check and build the $part_t2_2
So, the whole , complete code will be
See Demo