Exemple #1
0
 /**
  * Exclude elements with the same keys from input $data
  *
  * @param array $data
  */
 public function differ($data)
 {
     $data instanceof self && ($data = $data->toArray());
     $storage = $this->toArray();
     $this->exchangeArray(array_diff_key_recursive($storage, $data));
 }
function array_diff_key_recursive($array1, $array2)
{
    foreach ($array1 as $key => $value) {
        if (is_array($value) && array_key_exists($key, $array2)) {
            $result[$key] = array_diff_key_recursive($array1[$key], $array2[$key]);
        } else {
            if (is_array($value)) {
                $result[$key] = $array1[$key];
            } else {
                $result = array_diff_key($array1, $array2);
            }
        }
        if (is_array($result) && isset($result[$key]) && is_array($result[$key]) && count($result[$key]) == 0) {
            unset($result[$key]);
        }
    }
    return $result;
}