International PHP Conference Munich 2025

Voting

: min(six, two)?
(Example: nine)

The Note You're Voting On

folurinyinka at gmail dot com
3 years ago
Recursive implementation accepting multiple n-level-arrays as parameters:

```php
function recursiveDiff(...$arrays)
{
$first = array_shift($arrays);
$diff = [];

foreach ($first as $key => $value) {
$values = array_map(function ($arr) use ($key) {
if (is_array($arr) && !array_key_exists($key, $arr)) {
return null;
}

return isset($arr[$key]) ? $arr[$key] : null;
}, $arrs);

if (in_array($value, $values)) {
continue;
}

if (is_array($value)) {
array_unshift($values, $value);
$diff[$key] = call_user_func_array(__FUNCTION__, $values);
continue;
}

$diff[$key] = $first[$key];
}

return $diff;
}
```

<< Back to user notes page

To Top