#27644 [Opn->WFx]: array_merge reverses elements in first array
| From: | iliaa@php.net | Date: | Fri, 26 Mar 2004 19:45:22 +0000 |
| Subject: | #27644 [Opn->WFx]: array_merge reverses elements in first array | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-56920@lists.php.net to get a copy of this message | ||
ID: 27644
Updated by: iliaa@php.net
Reported By: ashok at yahoo-inc dot com
-Status: Open
+Status: Wont fix
Bug Type: *General Issues
Operating System: FreeBsd 4.3
PHP Version: 4.3.4
New Comment:
The problem is fixed in PHP5, however it cannot be
addressed in PHP 4 and hence marked won't fix.
Previous Comments:
------------------------------------------------------------------------
[2004-03-24 21:02:46] ashok at yahoo-inc dot com
Please see the index in your output. The first output shows array[1]
before array[0]. I think it should be top priority as it is changing
the array elments under you and you don't expect that. It's a random
behaviour.
Thanks.
-Ashok.
------------------------------------------------------------------------
[2004-03-23 13:37:10] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Works just fine. I've replaced your print code with
print_r(), which shows the correct order and here is what
you get:
Array
(
[1] => Text
[0] => 1
)
Array
(
[0] => Text
[1] => 1
[2] => 0
[3] => 0
[4] => 0
[5] => 0
[6] => 0
[7] => 0
[8] => 0
)
------------------------------------------------------------------------
[2004-03-18 20:25:59] ashok at yahoo-inc dot com
Description:
------------
When using array_merge to merge 2 arrays, the order
of elements of the first are changed. The keys are all integers unlike
other existing bugs where keys are mixed integers and strings.
Reproduce code:
---------------
<?php
$string1 = "1|Text|0-0-0-0-0-0-0";
list ($arr1[0], $arr1[1], $string2) = explode ("|", $string1, 3);
print ("Values of arr1 after first explode...\n");
for ($i = 0; $i < count ($arr1); $i++)
print ("arr1[$i] = " . $arr1[$i] . "\n");
print ("\nValues of arr1 after second explode...\n");
$arr1 = array_merge ($arr1, explode ('-', $string2));
for ($i = 0; $i < count ($arr1); $i++)
print ("arr1[$i] = " . $arr1[$i] . "\n");
?>
~
Expected result:
----------------
arr1[0] = 1
arr1[1] = Text
arr1[2] = 0
arr1[3] = 0
arr1[4] = 0
arr1[5] = 0
arr1[6] = 0
arr1[7] = 0
arr1[8] = 0
Actual result:
--------------
arr1[0] = Text
arr1[1] = 1
arr1[2] = 0
arr1[3] = 0
arr1[4] = 0
arr1[5] = 0
arr1[6] = 0
arr1[7] = 0
arr1[8] = 0
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=27644&edit=1