I need to test if one element of an array is in another array.
$array_one = array("gogo", "blabla", "toto");
$array_two = array("stackov", "renaul", "toto");
I would like to know if one element of array_one
is in array_two
???
How to test that? Am trying in_array
but it seems to have problems.
In NumPy, we can find common values between two arrays with the help intersect1d(). It will take parameter two arrays and it will return an array in which all the common elements will appear.
Using Arrays. equals(array1, array2) methods − This method iterates over each value of an array and compare using equals method. Using Arrays. deepEquals(array1, array2) methods − This method iterates over each value of an array and deep compare using any overridden equals method.
array_intersect()
$array1 = array("gogo", "blabla", "toto");
$array2 = array("stackov","renaul","toto");
$commonElements = array_intersect($array1,$array2);
var_dump($commonElements);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With