Re: PHP 4.0 Bug #4875: array_merge() is unable to merge arrays with numeric keys

From: Date: Wed, 07 Jun 2000 20:01:32 +0000
Subject: Re: PHP 4.0 Bug #4875: array_merge() is unable to merge arrays with numeric keys
References: 1 2 3  Groups: php.dev 
Request: Send a blank email to php-dev+get-20505@lists.php.net to get a copy of this message
1) Automatic conversion: Agreeing. It should really be possible to choose array indices which will not be converted to an integer if they consist of numbers only. If I choose $array=array('0'=>'foo',0=>'foo2'); I would like to have an array with two key/values pairs. 2) Array_Merge() It would help if array_merge() remembers numeric indices. $array=array(0=>'foo',5=>'boo',9=>'zoo'); $array2=array(4=>'loo',7=>'noo'); $res_array=array_merge($array,$array2); should result in $res_array(0=>'foo',5=>'boo',9=>'zoo',4=>'loo',7=>'noo'); An additional function could merge arrays loosing their numeric indices, eg. array_flat_merge()... regards wrote:
On Wed, Jun 07, 2000 at 01:05:34PM -0500, Andrei Zmievski wrote: On Wed, 07 Jun 2000, waldschrott@kiffen.de wrote:
From:             waldschrott@kiffen.de
Operating system: all
PHP version:      4.0.0 Release
PHP Bug Type:     Feature/Change Request
Bug description:  array_merge() is unable to merge arrays with numeric keys 
array_merge() is unable to merge arrays with numeric keys (as described in the documentation), however that´s usefull sometimes and should be possible, in face of the fact that even casting the keys to (string) they´re saved as (int)s.
Please describe in more detail how you want arrays with numeric keys to be merged. Here's an example: $a = array("a"=>"a"); $b = array("1"=>"b"); $c = array_merge($a, $b); while(list($k,$v)=each($c)) echo "$k:$v\n"; gives a:a 0:b but would be nice if got a:a 1:b when 1 is a string. The problem is not with array_merge, but with arrays in general I think. It seems that a numeric string like "1" is treated as an index and not a key. Would be nice if there was a difference, but fixing it might break a lot of existing PHP code I guess. Stig -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net For additional commands, e-mail: php-dev-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
o----------0-¬---------O-·---¬----o---®-----o o    O   °       .
| http://www.kiffen.de | pRoteçt y0ur bRaín |0  O °     ¤  °        ·
0°·³°²'²³-¹'³´³°^°³~³²³°'³²²¨³²^³¹³²°²³`³º³°Þ ° o © ° . ·
| psychedelic experience |  gott@kiffen.de  | O   ° o           °
o-¬--o--0-----©-·--O-----o-----0-¤----------o 0 ° · ° . ¤ ·

« previous php.dev (#20505) next »