#27644 [NEW]: array_merge reverses elements in first array

From: Date: Fri, 19 Mar 2004 01:25:59 +0000
Subject: #27644 [NEW]: array_merge reverses elements in first array
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-56655@lists.php.net to get a copy of this message
From: ashok at yahoo-inc dot com Operating system: FreeBsd 4.3 PHP version: 4.3.4 PHP Bug Type: *General Issues Bug description: array_merge reverses elements in first array 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 bug report at http://bugs.php.net/?id=27644&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=27644&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=27644&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=27644&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=27644&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=27644&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=27644&r=needscript Try newer version: http://bugs.php.net/fix.php?id=27644&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=27644&r=support Expected behavior: http://bugs.php.net/fix.php?id=27644&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=27644&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=27644&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=27644&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27644&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=27644&r=dst IIS Stability: http://bugs.php.net/fix.php?id=27644&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=27644&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=27644&r=float

« previous php.bugs (#56655) next »