Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62621 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7778 invoked from network); 1 Sep 2012 08:53:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Sep 2012 08:53:04 -0000 Authentication-Results: pb1.pair.com header.from=lester@lsces.co.uk; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=lester@lsces.co.uk; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lsces.co.uk from 213.123.20.131 cause and error) X-PHP-List-Original-Sender: lester@lsces.co.uk X-Host-Fingerprint: 213.123.20.131 c2bthomr13.btconnect.com Received: from [213.123.20.131] ([213.123.20.131:16641] helo=mail.btconnect.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E7/80-03671-DECC1405 for ; Sat, 01 Sep 2012 04:53:02 -0400 Received: from host81-138-11-136.in-addr.btopenworld.com (EHLO _10.0.0.5_) ([81.138.11.136]) by c2bthomr13.btconnect.com with ESMTP id IXF09335; Sat, 01 Sep 2012 09:52:58 +0100 (BST) Message-ID: <5041CCE7.1000309@lsces.co.uk> Date: Sat, 01 Sep 2012 09:52:55 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120604 Firefox/13.0 SeaMonkey/2.10 MIME-Version: 1.0 To: "internals@lists.php.net" References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Mirapoint-IP-Reputation: reputation=Fair-1, source=Queried, refid=tid=0001.0A0B0301.5041CCE8.00B2, actions=tag X-Junkmail-Premium-Raw: score=7/50, refid=2.7.2:2012.9.1.81815:17:7.944, ip=81.138.11.136, rules=__MOZILLA_MSGID, __HAS_MSGID, __SANE_MSGID, __HAS_FROM, __USER_AGENT, __MIME_VERSION, __TO_MALFORMED_2, __TO_NO_NAME, __BOUNCE_CHALLENGE_SUBJ, __BOUNCE_NDR_SUBJ_EXEMPT, __SUBJ_ALPHA_END, __CT, __CT_TEXT_PLAIN, __CTE, __ANY_URI, __URI_NO_MAILTO, __URI_NO_WWW, __CP_URI_IN_BODY, BODY_ENDS_IN_URL, BODYTEXTP_SIZE_3000_LESS, BODY_SIZE_1800_1899, __MIME_TEXT_ONLY, RDNS_GENERIC_POOLED, HTML_00_01, HTML_00_10, BODY_SIZE_5000_LESS, RDNS_SUSP_GENERIC, RDNS_SUSP, BODY_SIZE_2000_LESS, BODY_SIZE_7000_LESS X-Junkmail-Status: score=10/50, host=c2bthomr13.btconnect.com X-Junkmail-Signature-Raw: score=unknown, refid=str=0001.0A0B0203.5041CCEA.00F9:SCFSTAT14830815,ss=1,re=-4.000,fgs=0, ip=0.0.0.0, so=2011-07-25 19:15:43, dmn=2011-05-27 18:58:46, mode=multiengine X-Junkmail-IWF: false Subject: Re: [PHP-DEV] Support negative indexes for arrays and strings From: lester@lsces.co.uk (Lester Caine) Sherif Ramadan wrote: > As it stands today, that code would result in the following: > > $numbers = array(); > $numbers[-1] = 5; > $numbers[] = 6; > var_dump($numbers); > /* > array(2) { > [-1]=> > int(5) > [0]=> > int(6) > } > */ I think that it is just clarifying this further by adding $numbers = array(0,1,2,3,4); Which gives array(7) { [0]=> int(0) [1]=> int(1) [2]=> int(2) [3]=> int(3) [4]=> int(4) [-1]=> int(5) [5]=> int(6) } and foreach( $numbers as $value ) { print($value); } gives 0123456 as I would have expected! AND print( $numbers[-1] ); still returns '5' I can NOW use ksort() to really move the '5' to the top of the list. array(7) { [-1]=> int(5) [0]=> int(0) [1]=> int(1) [2]=> int(2) [3]=> int(3) [4]=> int(4) [5]=> int(6) } Bottom line ... perhaps we need a DIFFERENT means of identifying position in the array since using -ve keys IS a valid situation in real life. Personally I use -ve positions in the database tables to save having to process all records when adding items at the top, so the associative array quite correctly has -ve key values. I would not want PHP screwing around with that when reading the array in :) I think I am right in saying that 'real array' always start at 0 or 1, and positioning is explicit. So for simple stings then ne6ative indexes make perfect sense. But for PHP 'container arrays' we can legally have -ve keys, and removing that is simply not acceptable. -- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk