How To Check If Array Element Exists In Another Array In PHP
Posted by blogmeister on
April 15, 2013
This is the best 1 liner answer I found in the Internet to check if an array’s item or value or however you may call it exists in another array.
Using the function array_intersect(), you can achieve this. User lorenzo-s from Stack Overflow gave this 1 liner code that did the trick.
|
1 |
$found = (count($array2) == count(array_intersect($array2, $array1))); |
Do note that array_intersect() is case sensitive.
Donations appreciated. Every little $ helps. Or click Google +1.









