Re: Limit iterations on a foreach loop?

From: Date: Fri, 11 Feb 2005 16:10:24 +0000
Subject: Re: Limit iterations on a foreach loop?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-208521@lists.php.net to get a copy of this message
Brian Dunning wrote:
I'm using an RSS feed that has WAY too much content, I only want the first 10. I'm outputting the array with a foreach loop: is there a way to limit it to only go through the first 10? Thanks, - Brian
$i = 1; foreach ($rsses as $rss) {
    if ($i++ >= 10) {
        break;
    }
} However, why not use for()? for($i=0;$i<10;$i++) {
    // do stuff
    $rss = next($rsses);
} reset($rsses); Greg

« previous php.general (#208521) next »