Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix Arr::merge() to properly merge single dimension non-associative a…
…rrays, fixes #2945

Signed-off-by: Woody Gilk <woody.gilk@kohanaphp.com>
  • Loading branch information
cs278 authored and Woody Gilk committed Jun 26, 2010
1 parent 9ddd534 commit 0df3dfb
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions classes/kohana/arr.php
Expand Up @@ -287,6 +287,7 @@ public static function merge(array $a1, array $a2)
{
// Get the next array
$arr = func_get_arg($i);
$assoc = Arr::is_assoc($arr);

foreach ($arr as $key => $val)
{
Expand All @@ -310,8 +311,17 @@ public static function merge(array $a1, array $a2)
}
else
{
// Associative arrays are replaced
$result[$key] = $val;
if ($assoc)
{
// Associative array keys are replaced
$result[$key] = $val;
}
else if (!in_array($val, $result, true))
{
// Non associative entries are appended,
// only if they don't already exist.
$result[] = $val;
}
}
}
else
Expand Down

0 comments on commit 0df3dfb

Please sign in to comment.