Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53405 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77026 invoked from network); 20 Jun 2011 14:18:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jun 2011 14:18:48 -0000 Authentication-Results: pb1.pair.com smtp.mail=jbondc@openmv.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=jbondc@openmv.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain openmv.com from 64.15.152.204 cause and error) X-PHP-List-Original-Sender: jbondc@openmv.com X-Host-Fingerprint: 64.15.152.204 mail.ca.gdesolutions.com Received: from [64.15.152.204] ([64.15.152.204:57782] helo=mail.ca.gdesolutions.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 84/A1-34681-8C65FFD4 for ; Mon, 20 Jun 2011 10:18:48 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.ca.gdesolutions.com (Postfix) with ESMTP id A80D55D83; Mon, 20 Jun 2011 10:18:45 -0400 (EDT) X-Virus-Scanned: amavisd-new at gdesolutions.com Received: from mail.ca.gdesolutions.com ([127.0.0.1]) by localhost (mail.ca.gdesolutions.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id o0qOPbTT9qsZ; Mon, 20 Jun 2011 10:18:45 -0400 (EDT) Received: from djbondc (modemcable053.81-59-74.mc.videotron.ca [74.59.81.53]) by mail.ca.gdesolutions.com (Postfix) with ESMTPSA id CFC7C5D82; Mon, 20 Jun 2011 10:18:44 -0400 (EDT) To: "'Robert Eisele'" Cc: References: In-Reply-To: Date: Mon, 20 Jun 2011 10:18:43 -0400 Message-ID: <007c01cc2f54$f6a15bb0$e3e41310$@com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AcwvS7hr8zoVrh5eTwmuuAcbgOnvzAAA+Vxg Content-Language: en-ca Subject: RE: [PHP-DEV] foreach() for strings From: jbondc@openmv.com ("Jonathan Bond-Caron") On Mon Jun 20 09:11 AM, Lee davis wrote: >=20 > Could we also use current(), next() and key() for iteration of = strings? >=20 > $string =3D 'string'; > while ($char =3D current($string)) > { > echo key($string) // Would output the offset position I assume 0,1,2 > etc?? > echo $char // outputs each letter of string > next($string); > } >=20 Hopefully it can be supported without sacrificing too much performance Like others mentioned, it seems important to distinguish between = binary/byte and text iteration. $string =3D new ByteIterator('string =E9'); foreach($string as $i =3D> $byte)=20 ... $string =3D new TextIterator('string =E9'); foreach($string as $i =3D> $char)=20 ... When most developers get a 'string' from a database, my hunch is they = assume they would be iterating over the 'characters' (utf8, iso.. encoding) and = not individual bytes. So +1 to string iteration as long as there's byte iteration and some = plan for text iteration / by character (with icu or not).