Why array_diff() gives Array to string conversion error?

According to it:

php -r 'array_diff(array("a" => array("b" => 4)), array(1));'
PHP Notice:  Array to string conversion in Command line code on line 1
PHP Stack trace:
PHP   1. {main}() Command line code:0
PHP   2. array_diff() Command line code:1

One of your arrays is multidimensional.

array_diff only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using array_diff($array1[0], $array2[0]);


Yes, the strict answer is because "One of your arrays is multidimensional."

Another useful note might be - depending on your needs of further parsing the actual differences - consider first testing your arrays with:

$diff = strcmp(json_encode($stockist), json_encode($arr));

or

$diff = strspn(json_encode($stockist) ^ json_encode($arr), "\0");

or

$diff = xdiff_string_diff(json_encode($stockist), json_encode($arr));

All these options will compare the entire array tree, not just the top level.