I have two arrays, for example:
array1={1,2,3,4,5,6,7,8,9};
array2={4,6,9}
Is there any function so that I can determine that array2
fully exists in array1
?
I know i can use the in_array()
function in a loop but in cases where I will have large arrays with hundreds of elements so I am searching for a function.
Try:
$fullyExists = (count($array2) == count(array_intersect($array2, $array1));
The array_intersect.php
function will return only elements of the second array that are present in all the other arguments (only the first array in this case). So, if the length of the intersection is equal to the lenght of the second array, the second array is fully contained by the first one.
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