PHP 8 reference · Array Functions
PHP array_diff_assoc() Function
Return the entries of the first array whose key and value pair isn't in any of the other arrays.
PHP 8 Since 4.3
Syntax
array_diff_assoc(array $array, array ...$arrays): array
Parameters
| Parameter | Description |
|---|---|
array |
The input array. |
arrays |
Arrays to compare against. |
Return value
The entries whose key or value differs.
Examples
<?php
$old = ["name" => "Ada", "role" => "editor", "city" => "London"];
$new = ["name" => "Ada", "role" => "admin", "city" => "London"];
print_r(array_diff_assoc($new, $old));
Output
Array
(
[role] => admin
)<?php
print_r(array_diff(["a", "b"], ["b", "a"]));
print_r(array_diff_assoc(["a", "b"], ["b", "a"])); // positions differ
Output
Array
(
)
Array
(
[0] => a
[1] => b
)Version history
| Version | Change |
|---|---|
| PHP 4.3 | Added |
Related
array_diff()· Return the values of the first array that are not in any of the others. Values are compared as strings.array_diff_key()· Return the entries of the first array whose keys are not in any of the other arrays.- PHP Array Functions · tutorial
- PHP Arrays · tutorial