Skip to content

Commit

Permalink
fix bug in merge method of class Arr
Browse files Browse the repository at this point in the history
$array1 = ['a' => 'x'];
$array2 = ['a' => [1, 2]];
Arr::merge($array1, $array2);
above code wiil throw exception: Argument 1 passed to Hyperf\Collection\Arr::merge() must be of the type array, string given, called in ...
  • Loading branch information
liu3hu authored Oct 23, 2024
1 parent 7098171 commit d9d8b56
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,11 @@ public static function merge(array $array1, array $array2, bool $unique = true):
{
$isAssoc = static::isAssoc($array1 ?: $array2);
if ($isAssoc) {
foreach ($array2 as $key => $value) {
if (is_array($value)) {
$array1[$key] = static::merge($array1[$key] ?? [], $value, $unique);
foreach ($array2 as $key => $value2) {
if (is_array($value2) && isset($array1[$key]) && is_array($array1[$key])) {
$array1[$key] = static::merge($array1[$key], $value2, $unique);
} else {
$array1[$key] = $value;
$array1[$key] = $value2;
}
}
} else {
Expand Down

0 comments on commit d9d8b56

Please sign in to comment.