Re: Bug #14917: When using array_merge w/numbers & assoc array the numbers are changed to 0,1..
| From: | Steve Meyers | Date: | Tue, 08 Jan 2002 19:19:17 +0000 |
| Subject: | Re: Bug #14917: When using array_merge w/numbers & assoc array the numbers are changed to 0,1.. | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-76275@lists.php.net to get a copy of this message | ||
This is well documented in the comments for array_merge() in the manual. A
workaround is given -- the '+' operator is overloaded to do an associative
array merge when two arrays are given.
Blaine McDonnell wrote:
> From: blaine_mcdonnell@yahoo.com
> Operating system: BSD & Windows
> PHP version: 4.1.1
> PHP Bug Type: Output Control
> Bug description: When using array_merge w/numbers & assoc array the
> numbers are changed to 0,1..
>
> When I try to use array_merge an array with an associative array the array
> is renumbered starting at 0.
>
> Problem on Win2k with 4.1.0 & 4.1.1
> Problem on OpenBSD with 4.0.6
>
> Here is a quick sample:
>
> <?
> $TEST=array_merge(array(
"7"=>array(1=>"TEST",2=>"TEST",4=>"TEST"),"9"=>array(1=>"TEST",2=>"TEST",4=>"TEST")),array("A"=>array(1=>"TEST",2=>"TEST",4=>"TEST"),"B"=>array(1=>"TEST",2=>"TEST",4=>"TEST")));
> foreach ($TEST as $key=>$val)
> {print "$key<BR>";}
> ?>
>
> Output:
> 0
> 1
> A
> B