You are here: Re: Limit iterations on a foreach loop? « PHP « IT news, forums, messages
Re: Limit iterations on a foreach loop?

Posted by Greg Beaver on 02/11/05 18:10

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация