Re: oddity in array indexes

From: Date: Wed, 30 Apr 2003 16:29:51 +0000
Subject: Re: oddity in array indexes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-145815@lists.php.net to get a copy of this message
The code below works as expected in PHP 4.3.2RC2 as this bug was fixed. Here's the bug report: http://bugs.php.net/bug.php?id=22088 Regards, Philip On Wed, 30 Apr 2003, Joel Boonstra wrote: > Hi, > > I have found an oddity in the way PHP 4.3.1 does array indexes, and > wonder if others can replicate it for me. Here is some test code: > > <? > print '<pre>'; > $arr = array(1, 2, 3, 4); > print_r($arr); > $val = array_shift($arr); > print_r($arr); > $arr[] = $val; > print_r($arr); > print '</pre>'; > ?> > > I'm interested in the array indices in the printout. When I run that > code on a server running 4.3.1, the output is: > > Array > ( > [0] => 1 > [1] => 2 > [2] => 3 > [3] => 4 > ) > Array > ( > [0] => 2 > [1] => 3 > [2] => 4 > ) > Array > ( > [0] => 2 > [1] => 3 > [2] => 4 > [4] => 1 > ) > > Note the last array printout -- the last index is 4, rather than 3. > However, if you run that identical code on an earlier version of PHP the > indices display how I would expect them to: > > Array > ( > [0] => 1 > [1] => 2 > [2] => 3 > [3] => 4 > ) > Array > ( > [0] => 2 > [1] => 3 > [2] => 4 > ) > Array > ( > [0] => 2 > [1] => 3 > [2] => 4 > [3] => 1 > ) > > Also, if you do further array_shift() and array_push() or [] operations, > the indices don't get out of whack further -- that is, the last index > always remains at 4, but the first three are 0-2 as expected. > > Is this a bug, or just me missing something painfully obvious? Do other > folks see this behavior on recent-ish builds of PHP? I don't have 4.3.2 > handy to try it out on... > > -- > [ joel boonstra | jboonstra@gospelcom.net ] > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.general (#145815) next »