Bug #16269: array_splice produces an unexpected result

From: Date: Mon, 25 Mar 2002 20:34:17 +0000
Subject: Bug #16269: array_splice produces an unexpected result
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-3314@lists.php.net to get a copy of this message
From: saschahofmann@gmx.de Operating system: windows 2000 PHP version: 4.1.2 PHP Bug Type: Arrays related Bug description: array_splice produces an unexpected result Hi folks, I'm using PHP 4.1.2 as module with apache 1.3.23 I have this array: $array1[0] = array("a" => 3, "b" => 3); $array1[1] = array("a" => 9, "b" => 3); $array1[2] = array("a" => 11, "b" => 11); $array1[3] = array("a" => 11, "b" => 11); $array1[4] = array("a" => 15, "b" => 11); $array1[5] = array("a" => 2, "b" => 2); I want to split the array in to arrays with array1 containing all elements where a = b and array2 a <> b The correct result should be even: element 0,2,3,5 uneven: element 1,4 I used the following code to split the array: foreach ($array as $key = $val) { if ($val["a"] == $val["b"]) { $array2[] = array_splice($array1,$key,1); } } $array1 should now contain all uneven elements and $array2 all even elements (with a different structur but that doesn't matters here). But the result is: $array1 contains element 1,3,4 $array2 contains 4 elements but one is empty! The data of element 3 are missing. When I run the script with this comparison: if ($val["a"] != $val["b"]) I got the correct numbers of elements in each array (2 and 4) but with wrong values. I think this is a bug. Please inform me if you have investigated the issue and found a explanation (maybe I did something wrong). best, Sascha -- Edit bug report at http://bugs.php.net/?id=16269&edit=1 -- Fixed in CVS: http://bugs.php.net/fix.php?id=16269&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=16269&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=16269&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=16269&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=16269&r=support Expected behavior: http://bugs.php.net/fix.php?id=16269&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=16269&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=16269&r=submittedtwice

« previous php.bugs (#3314) next »