function drupal_array_diff_assoc_recursive
drupal_array_diff_assoc_recursive($array1, $array2)
Recursively computes the difference of arrays with additional index check.
This is a version of array_diff_assoc() that supports multidimensional arrays.
Parameters
array $array1: The array to compare from.
array $array2: The array to compare to.
Return value
array Returns an array containing all the values from array1 that are not present in array2.
File
- includes/common.inc, line 6663
- Common functions that many Drupal modules will need to reference.
Code
function drupal_array_diff_assoc_recursive($array1, $array2) { $difference = array(); foreach ($array1 as $key => $value) { if (is_array($value)) { if (!array_key_exists($key, $array2) || !is_array($array2[$key])) { $difference[$key] = $value; } else { $new_diff = drupal_array_diff_assoc_recursive($value, $array2[$key]); if (!empty($new_diff)) { $difference[$key] = $new_diff; } } } elseif (!array_key_exists($key, $array2) || $array2[$key] !== $value) { $difference[$key] = $value; } } return $difference; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!common.inc/function/drupal_array_diff_assoc_recursive/7.x