Bug #14917 Updated: When using array_merge w/numbers & assoc array the numbers are changed to 0,1..
| From: | andrei@php.net | Date: | Wed, 24 Apr 2002 14:50:22 +0000 |
| Subject: | Bug #14917 Updated: When using array_merge w/numbers & assoc array the numbers are changed to 0,1.. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-5833@lists.php.net to get a copy of this message | ||
ID: 14917
Updated by: andrei@php.net
Reported By: blaine_mcdonnell@yahoo.com
-Status: Open
+Status: Closed
Bug Type: Arrays related
Operating System: BSD & Windows
PHP Version: 4.1.1
New Comment:
This happens because of the way PHP treats array keys that are quoted
numbers, that is, "7" is really an integer key 7 and those do get
renumbered by array_merge() as it's supposed to work this way.
Previous Comments:
------------------------------------------------------------------------
[2002-03-22 17:00:08] blaine_mcdonnell@yahoo.com
Still a problem in 4.1.2
------------------------------------------------------------------------
[2002-02-18 15:23:44] blaine_mcdonnell@yahoo.com
This is the work around I used:
function my_array_merge()
{
$DATA_ARRAY=func_get_args();
foreach ($DATA_ARRAY as $key=>$val)
{
foreach (testArray($DATA_ARRAY[$key]) as $key1=>$val1)
{$TEMP_ARRAY[$key1]=$DATA_ARRAY[$key][$key1];}
}
return $TEMP_ARRAY;
}
------------------------------------------------------------------------
[2002-01-08 07:19:40] sander@php.net
Reclassified.
------------------------------------------------------------------------
[2002-01-07 16:01:29] blaine_mcdonnell@yahoo.com
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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=14917&edit=1