NYCPHP Meetup

NYPHP.org

[nycphp-talk] string function

David Mintz david at davidmintz.org
Thu Jul 3 13:10:09 EDT 2008


On Thu, Jul 3, 2008 at 12:45 PM, Michael Southwell <
michael.southwell at nyphp.com> wrote:

> John Campbell wrote:
>
>> $p = explode('|',$y);
>> for($i=0,$c = count($p);$i<$c;) {
>> echo $p[$i++],' ', $p[$i++], "<br>\n";
>> }
>>
>
> I believe this will miss the first element of $p; you need instead:
>
> for ( $i = -1, $c = count( $p ); $i < $c; ) {
>
>
Although calling count() repreatedly is also more expensive than doing it
once and saving its value in a variable, isn't it?

and.... aren't you glad this guy asked this question?

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20080703/78a61b1e/attachment.html>


More information about the talk mailing list