You are here

function icon_array_diff_recursive in Icon API 8

Same name and namespace in other branches
  1. 7 includes/utilities.inc \icon_array_diff_recursive()

Determine the recursive differences between two arrays.

Parameters

array $array1: The first array.

array $array2: The second array.

Return value

array If $array2 differs in any way from $array1, the differences will be returned in an array. If there are no differences, the array will be empty.

1 call to icon_array_diff_recursive()
icon_bundle_save in ./icon.module
Save an icon bundle in the {icon_bundle} table.

File

includes/utilities.inc, line 130
utilities.inc Provides useful functions and common tasks.

Code

function icon_array_diff_recursive(array $array1, array $array2) {
  $diff = array();
  foreach ($array2 as $key => $value) {
    if (array_key_exists($key, $array1)) {
      if (is_array($value)) {
        $recursive_diff = icon_array_diff_recursive($array1[$key], $value);
        if (count($recursive_diff)) {
          $diff[$key] = $recursive_diff;
        }
      }
      else {
        if ($value !== $array1[$key]) {
          $diff[$key] = $value;
        }
      }
    }
    else {
      $diff[$key] = $value;
    }
  }
  return $diff;
}