#24159 [Ver]: Php starts indexing from zero if lowest index is negative
| From: | iliaa@php.net | Date: | Mon, 04 Aug 2003 21:03:16 +0000 |
| Subject: | #24159 [Ver]: Php starts indexing from zero if lowest index is negative | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969355558@lists.php.net to get a copy of this message | ||
ID: 24159
Updated by: iliaa@php.net
Reported By: rsen010 at ec dot auckland dot ac dot nz
Status: Verified
-Bug Type: Scripting Engine problem
+Bug Type: Documentation problem
Operating System: Any
PHP Version: 4.3.2, 5.0.0b2-dev
New Comment:
This is a documentation issue. The change was made to avoid possible
crashes.
Previous Comments:
------------------------------------------------------------------------
[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