You are here

public function FlexiformElementField::diffArrays in Flexiform 7

Get the Difference of two settings arrays.

@todo: Build in special casing for default values.

See also

http://uk1.php.net/manual/en/function.array-diff-assoc.php#111675

1 call to FlexiformElementField::diffArrays()
FlexiformElementField::configureFormSubmit in includes/element/field.element.inc
Overrides FlexiformElement::configureFormSubmit().

File

includes/element/field.element.inc, line 159
Contains FlexiformElementField class.

Class

FlexiformElementField
Class for Field API elements.

Code

public function diffArrays($array, $original_array) {
  $difference = array();
  foreach ($array as $key => $value) {
    if (is_array($value)) {
      if (!isset($original_array[$key]) || !is_array($original_array[$key])) {
        $difference[$key] = $value;
      }
      else {
        $new_diff = $this
          ->diffArrays($value, $original_array[$key]);
        if (!empty($new_diff)) {
          $difference[$key] = $new_diff;
        }
      }
    }
    elseif (!array_key_exists($key, $original_array) || $original_array[$key] !== $value) {
      $difference[$key] = $value;
    }
  }
  return $difference;
}