array_intersect and array_intersect_assoc
- These both functions are basically used to find the common elements between two arrays.
- Basic difference above function is
array_intersect()
- returns the common elements which are having same value
array_intersect_assuc()
- returns the common elements which are having same key and value.
Example:
$arr1 = array("index1" => "one", "index2" => "two", "index3" => "three", "four");
$arr2 = array("index1" => "one", "three","four");
$resArr = array_intersect_assoc($arr1, $arr2);
print_r($resArr);
$resArr2 = array_intersect($arr1, $arr2);
print_r($resArr2);
In the above example first print_r() will give only one value(one). Because only one element in both arrays are having same key and value.
Second print_r() will give one,three and four.
