Skip to content

Commit

Permalink
fixed multidimensional fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Feb 12, 2021
1 parent 44a193f commit 7ac79e8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Contracts/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function load($force = false)
$fallback_data = $this->with_fallback ? config('setting.fallback') : [];
$driver_data = $this->readData();

$this->data = array_merge((array) $fallback_data, (array) $driver_data);
$this->data = Arr::merge((array) $fallback_data, (array) $driver_data);
$this->loaded = true;
}

Expand Down
27 changes: 27 additions & 0 deletions src/Support/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,31 @@ public static function forget(array &$data, $key)

unset($data[$key]);
}

/**
* Merge two multidimensional arrays recursive
*
* @param array $array_1
* @param array $array_2
*
* @return array
*/
public static function merge(array $array_1, array $array_2)
{
$merged = $array_1;

foreach ($array_2 as $key => $value) {
if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
$merged[$key] = static::merge($merged[$key], $value);
} elseif (is_numeric($key)) {
if (!in_array($value, $merged)) {
$merged[] = $value;
}
} else {
$merged[$key] = $value;
}
}

return $merged;
}
}

0 comments on commit 7ac79e8

Please sign in to comment.