Re: Re: [PHP-DEV] Support negative indexes for arrays and strings

From: Date: Sun, 02 Sep 2012 01:10:05 +0000
Subject: Re: Re: [PHP-DEV] Support negative indexes for arrays and strings
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-62647@lists.php.net to get a copy of this message
On 2012-09-01 21:23, Sherif Ramadan wrote:
$array[0] = 'first element'; $array[99999] = 'second element'; var_dump($array); /* array(2) { [99999]=> string(14) "second element" [0]=> string(13) "first element" } */
Just correcting this as it was a copy/paste fail... The above code would produce: array(2) { [0]=> string(13) "first element" [99999]=> string(14) "second element" }
Or: <?php $array = []; $array[1] = 42; $array[0] = 17; $array[2] = 99; print_r($array); ?> And, just to be explicit, following that up with: <?php reset($array); echo key($array),"\t",current($array),"\n"; next($array); echo key($array),"\t",current($array),"\n"; next($array); echo key($array),"\t",current($array),"\n"; ?> ===> Array (
    [1] => 42
    [0] => 17
    [2] => 99
)
1       42
0       17
2       99


« previous php.internals (#62647) next »