How does one compare two arrays?
For example--I have two arrays. I would like a simple true/false as to whether any values from array 1 appear in array 2. in_array will only search for a single value no? A loop would work I'm sure, but there has to be a more elegant way...
Thoughts? Thanks.
Array Comparison
Moderator: General Moderators
Re: Array Comparison
You might be looking for array_diff().
Re: Array Comparison
I did have that in mind. What does array_diff() return if it finds nothing in common among arrays? Thanks.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Array Comparison
Code: Select all
if(array_intersect($array2, $array1)) {mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.