#objective
to propagate how great built-in functions are
baseline
$arr1 = ["a", "b"];
$arr2 = ["a", "c"];
var_export(array_intersect($arr1, $arr2));
//array (
// 0 => 'a',
//)
Note: Two elements are considered equal if and only if (string) $elem1 === (string) $elem2. In words: when the string representation is the same.
-- array_intersect/note
so what if the parameters were arrays of array(and so on)?
$arr3 = [["a"], ["b"]];
$arr4 = [["a"], ["c"]];
var_export(array_intersect($arr1, $arr2));
// this causes "PHP Notice: Array to string conversion"
// and echoes
// array (
// 0 =>
// array (
// 0 => 'a',
// ),
// 1 =>
// array (
// 0 => 'b',
// ),
// )
// because (string)["a"] or (string)["b"] or (string)["c"] should be "Array"
solution
use array_uintersect;
var_export(array_uintersect($arr3, $arr4, function($a, $b) { if ($a == $b) return 0; else return -1;}));
//array (
// 0 => 'a',
//)
and read document.