Compare PHP Arrays Online
Paste two PHP arrays (as JSON). See what was added, removed, or changed — element by element.
🔒 100% private — runs entirely in your browseror try sample data
Paste two PHP arrays (as JSON). See what was added, removed, or changed — element by element.
🔒 100% private — runs entirely in your browseror try sample data
PHP Array Diff compares two PHP arrays and shows exactly what changed. PHP has several built-in functions for array comparison — array_diff(), array_diff_assoc(), array_diff_key() — but none provide a visual, side-by-side view of the differences.
PHP arrays are uniquely versatile: they serve as both indexed lists and associative maps (dictionaries). This dual nature means array comparison in PHP often requires choosing the right function for the job. This tool handles both cases by comparing structures recursively.
Paste your arrays as JSON. Indexed arrays use [1, 2, 3] syntax; associative arrays use {"key": "value"}. The tool compares at any nesting depth, far beyond what PHP's native array_diff() offers.
$arr1 = ['laravel', 'symfony', 'codeigniter', 'slim'];
$arr2 = ['laravel', 'symfony', 'livewire', 'slim', 'pest']; $removed = array_diff($arr1, $arr2);
$added = array_diff($arr2, $arr1); print_r($removed); // [2 => 'codeigniter']
print_r($added); // [2 => 'livewire', 4 => 'pest']array_diff compares values but preserves original keys, which can be confusing.
$config1 = ['db' => 'mysql', 'cache' => 'redis', 'debug' => true];
$config2 = ['db' => 'postgres', 'cache' => 'redis', 'queue' => 'sqs']; $diff = array_diff_assoc($config1, $config2);
print_r($diff);
// ['db' => 'mysql', 'debug' => true]array_diff_assoc checks both keys and values but only returns items from the first array.
function array_diff_recursive($arr1, $arr2) { $diff = []; foreach ($arr1 as $key => $value) { if (is_array($value)) { $diff[$key] = array_diff_recursive( $value, $arr2[$key] ?? [] ); } elseif (!isset($arr2[$key]) || $arr2[$key] !== $value) { $diff[$key] = $value; } } return array_filter($diff);
}PHP has no built-in deep array diff — you need a custom recursive function or this tool.
array_diff() uses loose (==) comparison. This means 0 == "foo" is true in PHP 7, causing phantom matches. Use array_diff() with === via array_filter or strict comparison functions when types matter.
array_diff() preserves the original array keys. After diffing, your result may have gaps like [2 => 'x', 5 => 'y'] instead of a clean re-indexed array. Use array_values() to re-index if needed.
PHP's array_diff() only compares the first level. Nested arrays are compared by reference, not by value. For multidimensional arrays, you need a recursive implementation or this online tool.
Paste your PHP arrays as JSON format into the two panels and click Compare. Indexed arrays use [1, 2, 3] syntax and associative arrays use {"key": "value"}.
array_diff() compares values only, ignoring keys. array_diff_assoc() compares both keys and values. For most real-world use cases with associative arrays, you want array_diff_assoc().
Yes. Paste associative arrays as JSON objects ({"key": "value"}). The tool compares keys and values structurally.
Yes. Everything runs in your browser. No PHP data is sent to any server.
Yes. The tool performs deep recursive comparison at any nesting level — something PHP's built-in array_diff() cannot do.
The tool expects JSON format. Convert PHP syntax: replace array() with [], use double quotes for keys, and replace => with :.