lithium\util\Set::diff()
Computes the difference between two arrays.
Parameters
-
array
$val1
First value.
-
array
$val2
Second value.
Returns
arrayComputed difference.
Source
public static function diff(array $val1, array $val2) {
if (!$val1 || !$val2) {
return $val2 ?: $val1;
}
$out = [];
foreach ($val1 as $key => $val) {
$exists = isset($val2[$key]);
if (($exists && $val2[$key] !== $val) || !$exists) {
$out[$key] = $val;
}
unset($val2[$key]);
}
foreach ($val2 as $key => $val) {
if (!isset($out[$key])) {
$out[$key] = $val;
}
}
return $out;
}