Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46595 Return-Path: <0xcafefeed@gmail.com> Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 15280 invoked from network); 2 Jan 2010 22:32:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Jan 2010 22:32:42 -0000 Authentication-Results: pb1.pair.com smtp.mail=0xcafefeed@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=0xcafefeed@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.78.25 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: 0xcafefeed@gmail.com X-Host-Fingerprint: 74.125.78.25 ey-out-2122.google.com Received: from [74.125.78.25] ([74.125.78.25:5703] helo=ey-out-2122.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D4/05-12956-989CF3B4 for ; Sat, 02 Jan 2010 17:32:42 -0500 Received: by ey-out-2122.google.com with SMTP id 9so2585096eyd.39 for ; Sat, 02 Jan 2010 14:32:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=TX3DH8bNNNS6CzX9R1km+GROBDkaOIl7EYQGspLSZ0Y=; b=rGLWJchAL/35nvSTF7y3VKkfs5zKyJW29Uw0HU8Ja2xnaNhhu1h6dXr5uea4CC2MIx bVgg6xEhYADdDTeyM9obOqxUCXXomQ/unbMVYuh0sKxDdLenw0bQFcvNI4/abceM2Vrq zWGlF2Qejvwjs8mrErfUvtqnKhiLoPAGcUuec= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=WoLk7yp4TVIvWPfgrnZbhG5ptKOhuS4jVIU7ZcehOldr56rdUOFCLMtU6F3Jr1JXzc /0yFu9xOP9lskzu+qrQyrN/35doZ0mkycORXdC9UsO2wC4mOFhtYX0dTMzqsJz+NEPqV 8ShfW9PRRv67PDxYwIGgus2B8FsvBuhJknrco= MIME-Version: 1.0 Received: by 10.216.91.73 with SMTP id g51mr7808585wef.68.1262471558827; Sat, 02 Jan 2010 14:32:38 -0800 (PST) In-Reply-To: <4B3F788E.7090200@gmail.com> References: <4B3F788E.7090200@gmail.com> Date: Sat, 2 Jan 2010 14:32:38 -0800 Message-ID: To: Oskar Eisemuth Cc: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] array position isfirst / islast / valid ? From: 0xcafefeed@gmail.com (mm w) reversed =3D $reversed; $this->arr =3D $arr; if ($this->reversed) { end($this->arr); } } =09 public function first() { if ($this->reversed) { $cnt =3D count($this->arr); $idx =3D $cnt > 1 ? $cnt - 1 : 0; } else { $idx =3D 0; } return $this->arr[$idx]; } =09 public function last() { if ($this->reversed) { $idx =3D 0; } else { $cnt =3D count($this->arr); $idx =3D $cnt > 1 ? $cnt - 1 : 0; } return $this->arr[$idx]; } =09 public function isfirst() { if ($this->reversed) { $cnt =3D count($this->arr); $idx =3D $cnt > 1 ? $cnt - 1 : 0; } else { $idx =3D 0; } return key($this->arr) =3D=3D $idx; } =09 public function islast() { if ($this->reversed) { $idx =3D 0; } else { $cnt =3D count($this->arr); $idx =3D $cnt > 1 ? $cnt - 1 : 0; } return key($this->arr) =3D=3D $idx; } =09 public function rewind() { if ($this->reversed) { end($this->arr); } else { reset($this->arr); } } =09 public function current() { return current($this->arr); } =09 public function key() { return key($this->arr); } =09 public function end() { if ($this->reversed) { reset($this->arr); } else { end($this->arr); } } public function next() { if ($this->reversed) { return prev($this->arr); } else { return next($this->arr); } } =09 public function prev() { if ($this->reversed) { return next($this->arr); } else { return prev($this->arr); } } public function valid() { $current =3D $this->current(); return !empty($current) && $current !=3D null; } }; class MArray implements FastEnumeration { private $arr; =09 public function getIterator() { return new Enumerator($this->arr); } public function reverseEnumerator() { return new Enumerator($this->arr, EnumerationReverse); } public function concurrentEnumerator() { return new Enumerator($this->arr, EnumerationConcurrent); } // ... }; /* EOF */ ?> On Sat, Jan 2, 2010 at 8:47 AM, Oskar Eisemuth wrote: > Hello > > Would it be possible to add functions to know the relative internal array > position? > > I found "[PHP-DEV] RFC array functions" from 2006, but nothing really > changed. > > The need to use next, prev in combination is ridiculous compared to a cle= an > array_hasmore or array_pos_islast, as the internals already know this. > To get an array_valid_position or array_pos_isvalid wouldn't be bad eithe= r. > > So would it possible to introduce: > > array_pos_isfirst(& =C2=A0$array) > array_pos_islast(& =C2=A0$array) > array_pos_isvalid(& =C2=A0$array) > > > Best regards > Oskar Eisemuth > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >