DiffArray.php in Drupal 10
File
core/lib/Drupal/Component/Utility/DiffArray.php
View source
<?php
namespace Drupal\Component\Utility;
class DiffArray {
public static function diffAssocRecursive(array $array1, array $array2) {
$difference = [];
foreach ($array1 as $key => $value) {
if (is_array($value)) {
if (!array_key_exists($key, $array2) || !is_array($array2[$key])) {
$difference[$key] = $value;
}
else {
$new_diff = static::diffAssocRecursive($value, $array2[$key]);
if (!empty($new_diff)) {
$difference[$key] = $new_diff;
}
}
}
elseif (!array_key_exists($key, $array2) || $array2[$key] !== $value) {
$difference[$key] = $value;
}
}
return $difference;
}
}
Classes
Name |
Description |
DiffArray |
Provides helpers to perform diffs on multi dimensional arrays. |