#27644 [Opn->Bgs]: array_merge reverses elements in first array
ID: 27644
Updated by: iliaa@php.net
Reported By: ashok at yahoo-inc dot com
-Status: Open
+Status: Bogus
Bug Type: *General Issues
Operating System: FreeBsd 4.3
PHP Version: 4.3.4
New Comment:
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
)
Previous Comments:
------------------------------------------------------------------------
[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
Thread (4 messages)