array_merge bug ?

This is a discussion on array_merge bug ? within the PHP Language forums, part of the PHP Programming Forums category; Hi, This is my code : ######## $Table1 = array('test' => 1, '432' => 2) ; $Table2 = array('test2' => 1) ; $Result = array_merge($...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-07-2007
cornelius
 
Posts: n/a
Default array_merge bug ?

Hi,

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

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

echo "<pre>Table1=" . print_r($Table1, 1) . "</pre>";
echo "<pre>Table2=" . print_r($Table2, 1) . "</pre>";
echo "<pre>Result=" . print_r($Result, 1) . "</pre>";
########

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


Reply With Quote
  #2 (permalink)  
Old 08-07-2007
cornelius
 
Posts: n/a
Default Re: array_merge bug ?

I've just found the solution :

$Result = $Table1 + $Table2 ;

is better than :

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



// Cornelius


Reply With Quote
  #3 (permalink)  
Old 08-07-2007
gosha bine
 
Posts: n/a
Default Re: array_merge bug ?

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:46 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0