array_merge bug ?

array_merge bug ?

am 07.08.2007 19:07:47 von Cornelius

Hi,

This is my code :
########
$Table1 = array('test' => 1, '432' => 2) ;
$Table2 = array('test2' => 1) ;

$Result = array_merge($Table1, $Table2) ;

echo "

Table1=" . print_r($Table1, 1) . "
";
echo "
Table2=" . print_r($Table2, 1) . "
";
echo "
Result=" . print_r($Result, 1) . "
";
########

And the result is :

########
Table1=Array
(
[test] => 1
[432] => 2
)
Table2=Array
(
[test2] => 1
)
Result=Array
(
[test] => 1
[0] => 2
[test2] => 1
)
########

The '432' key has become 0 !
Is it a bug (I couldn't find it over google) ?

How to keep the '432' key in the result ?

Thanks in advance,


// Cornelius

Re: array_merge bug ?

am 07.08.2007 19:12:03 von Cornelius

I've just found the solution :

$Result = $Table1 + $Table2 ;

is better than :

$Result = array_merge($Table1, $Table2) ;



// Cornelius

Re: array_merge bug ?

am 07.08.2007 22:18:26 von gosha bine

cornelius wrote:
> Hi,
>
> This is my code :
> [snip]
> The '432' key has become 0 !
> Is it a bug (I couldn't find it over google) ?
>
> How to keep the '432' key in the result ?

This is documented, see array_merge manual page.


--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok