php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20833 where is the third element?
Submitted: 2002-12-05 11:31 UTC Modified: 2002-12-05 12:28 UTC
From: mk75 at virgilio dot it Assigned:
Status: Closed Package: Arrays related
PHP Version: 4.2.3 OS: windows 2000Pro
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mk75 at virgilio dot it
New email:
PHP Version: OS:

 

 [2002-12-05 11:31 UTC] mk75 at virgilio dot it
<?php $fruits= array ("first", -1 => "second","third" ); ?>

   <?php echo $fruits[0] ?> // print first
                  </p>
   <?php echo $fruits[-1];?> // print second
                  </p>
   <?php echo $fruits[1];?> // Notice: Undefined offset: 1
                  </p>
   <?php echo count($fruits) ?> // print 2!

What's the key for element "third"?
why array's size is 2?

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-05 12:28 UTC] derick@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.

I could reproduce this with 4.2.3 (on linux) but not anymore with 4.3.0RC2. The array index of "third" is 1 as expected too. 
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 05:01:33 2025 UTC