php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10264 strange associative array behaviour
Submitted: 2001-04-10 12:33 UTC Modified: 2002-03-31 00:00 UTC
From: shane dot wright at ecustomeropinions dot com Assigned:
Status: No Feedback Package: Arrays related
PHP Version: 4.0.4pl1 OS: RedHat 7
Private report: No CVE-ID:
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: shane dot wright at ecustomeropinions dot com
New email:
PHP Version: OS:

 

 [2001-04-10 12:33 UTC] shane dot wright at ecustomeropinions dot com
Not sure if this is a bug or not, but I can't find any 
reference to it in the documentation/user comments/FAQs

Basically, if you build an associative(ish) array like 
this:

$period = -24;
for ($i=$period; $i<=0; $i++) {
	$data[$i] = $myvalues[$anotherindex];
};

It works ok, the array contains (in order) elements with 
the inidices -24 to 0.

But, if $period is decreased so that over 25 elements are 
introduced, the order goes off...

basically elements with indices -24 to 0 are fine, but all 
the other ones come, in order, _after_ index 0.

Any ideas?

Shane

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-05-19 13:06 UTC] jeroen@php.net
I.M.O. negative integer indices are not supported. It is just a side-effect of the implementation that it works.

I haven't seen ANY language supporting negative array-indices.

You can use the real assosiative version though:

$data["$i"] = ...

And don't forget to use the same syntax when collecting the data.
 [2001-05-21 14:08 UTC] cynic@php.net
IIRC PHP converts numeric strings in array indices to numbers, so array( "1" => "foo" , "2" => "bar" ) actually creates array( 1 => "foo" , 2 => "bar" ). IE the proposed method won't work.
 [2002-02-26 21:39 UTC] yohgaki@php.net
Is this stiall a issue?
 [2002-02-26 21:39 UTC] yohgaki@php.net
s/stiall/still/g
 [2002-03-31 00:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Aug 29 15:01:52 2017 UTC