I hope this question has a really quick, simple answer. I have two arrays and I'd like to quickly compare them to see if they match and, if they don't match, what their differences are. Ideally the output would be a string like what you get from diff filea fileb
.
I could certainly write a function to create two temporary files and call diff, but was wondering if there's some PHP function that will generate such a string for two arrays or strings. I have in the past always had to perform two array_diff
calls:
$a = [1,2,3];
$b = [3,4,5];
echo "a not b\n";
print_r()array_diff($a, $b));
echo "b not a\n";
print_r()array_diff($b, $a));
which is quite clunky, IMHO. Also, the output shows one array's extras and then the other array's extras and doesn't give you a feel for the differences item-by-item as they occur.