#24159 [Ver->Csd]: Php starts indexing from zero if lowest index is negative
| From: | vrana@php.net | Date: | Sat, 07 Aug 2004 14:30:22 +0000 |
| Subject: | #24159 [Ver->Csd]: Php starts indexing from zero if lowest index is negative | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969362842@lists.php.net to get a copy of this message | ||
ID: 24159
Updated by: vrana@php.net
Reported By: rsen010 at ec dot auckland dot ac dot nz
-Status: Verified
+Status: Closed
Bug Type: Documentation problem
Operating System: Any
PHP Version: 4.3.2, 5.0.0b2-dev
New Comment:
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at
http://www.php.net/downloads.php
"As of PHP 4.3.0, the index generation behaviour described above has
changed. Now, if you append to an array in which the current maximum
key is negative, then the next key created will be zero (0). Before,
the new index would have been set to the largest existing key + 1, the
same as positive indices are."
Previous Comments:
------------------------------------------------------------------------
[2003-08-04 16:03:15] iliaa@php.net
This is a documentation issue. The change was made to avoid possible
crashes.
------------------------------------------------------------------------
[2003-08-03 19:40:43] et@php.net
This behaviour was introduced in 4.3.0 - reclassifying as an array
problem.
I don't know if the behaviour or the documentation should be changed.
------------------------------------------------------------------------
[2003-06-12 15:38:20] rsen010 at ec dot auckland dot ac dot nz
Description:
------------
Hi,
When I was going through Chapter 7.types in PHP manual I found
something confusing regarding the following statement Having e.g. the
highest index being -6 will result in -5 being the new key (under
Syntax specifying with array()).What actually happens is it Php
starts indexing from zero if lowest index is negative value unless
there is no index of zero.
But amazing thing is sometimes it omit some values unless.
Just consider the following examples.
Ex:1
$a = array(-3=>'February', 'March');
print_r($a);
This will prints out the folloiwng
> Array ( [-3] => February [0] => March )
Ex:2
$a = array( 'January', '0'=>'a','b',
'c',-3=>'February', 'March');
print_r($a);
This will prints out the folloiwng
Array ( [0] => a [1] => b [2] => c [-3] => February [3] => March )
Please be kind to check this out if Im correct and reply me.
Thanks
Naleen
Reproduce code:
---------------
$a = array(-3=>'February', 'March');
print_r($a);
$a = array( 'January', '0'=>'a','b',
'c',-3=>'February', 'March');
print_r($a);
Expected result:
----------------
Array (-3=>February, [-2] => March );
Array ( [1]=>January [0] => a [2] => b [3] => c [-3] => February [4] =>
March )
Actual result:
--------------
Array ([-3] => February [0] => March )
Array ( [0] => a [1] => b [2] => c [-3] => February [3] => March )
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=24159&edit=1