Reputation: 32653
I want to compare 2 arrays by values and not keys. For example:
$array1 = array(0 => 'wow', 1 => 'foo', 2 => 'bar');
$array2 = array(0 => 'foo', 1 => 'wow', 2 => 'bar');
are not unique.
Is there any function for this?
Thanx!
Upvotes: 0
Views: 122
Reputation: 11502
http://www.php.net/manual/en/function.array-intersect.php
array_intersect(
array('wow','foo','bar','baz'),
array('foo','wow','bar','fiz'),
)
// Output
// [ 'wow', 'foo', 'bar' ]
Upvotes: 1
Reputation: 34673
array_diff() - Compares array1 against array2 and returns the difference.
array_diff_assoc() - Computes the difference of arrays with additional index check
Upvotes: 1