You need to convert the JSON objects to arrays first and then find the difference between the two arrays. To convert a JSON string into an array use json_decode()
with true
as second parameter:
$firstArray = json_decode($first, true);
If you leave the second parameter out, $firstArray would be an object, that is an instance of stdClass
.
But first you'd need the content of the file as a string, so better use file_get_contents()
:
$first = file_get_contents('lalala.json');
Update:
Even when you've converted the JSON strings properly into array, you'll still have a problem, as array_diff()
only works with one dimensional arrays, as it's mentioned in the Notes
section of the documentation. To be able to use in on multidimensional arrays, have a look at this comment to the documentation.