PHP array_diff vs array_diff_assoc vs array_diff_key
PHP ships multiple array comparison functions, but each answers a different question. Use the right one before you fall back to custom recursive code.
The main PHP array comparison mistake is choosing the wrong built-in function. array_diff(), array_diff_assoc(), and array_diff_key() look similar, but they compare different parts of the array and return different kinds of results.
array_diff compares values only
$left = ['framework' => 'laravel', 'cache' => 'redis'];
$right = ['framework' => 'laravel', 'cache' => 'memcached']; $result = array_diff($left, $right);This tells you which values from the first array do not appear in the second. It ignores keys, which can be surprising when you are working with associative arrays.
array_diff_assoc compares keys and values
Use array_diff_assoc() when the key-value pairing is what matters. This is usually the correct choice for associative configuration arrays because it distinguishes the same value appearing under different keys.
array_diff_key compares keys only
Use array_diff_key() when you only care about which fields exist, not what their values contain. This is useful for schema-like checks such as optional config flags or missing response fields.
What PHP still does not solve
None of these functions gives you a friendly, recursive, side-by-side diff for nested structures. Once the array contains nested arrays or mixed object-like data, you are usually writing custom recursion or installing a helper package.
When to switch to ArrayDiff
Use PHP Array Diff when you need a visual answer instead of a raw PHP return value. For dict-style payloads serialized as JSON, PHP JSON Diff is often the better fit. If you are still deciding between related pages, use the Array Comparison Tools hub.