You are here: Re: Stuck with foreach & while « All PHP « IT news, forums, messages
Re: Stuck with foreach & while

Posted by Juliette on 11/24/05 21:43

mike wrote:
> I have a large array containing approx 800 items, then below I have this
> code
>
> foreach ($myarray as $value) {
> $index++;
> print($index . ". ");
> print($value);
> }
>
> the end result is something like this:
>
> 1. Blah Blah Blah
> 2. Yada Yada Yada
> 3. one two three
>
> However, I'd like to break up the 800 lines into smaller chunks, say 100 per
> page but can't quite work out how to intergrate my foreach loop with a while
> loop? I want to it to be like "while $index is less than 101 print(stuff) ".
> The part I'm stuck on seems to be getting this part of my foreach loop
> ($myarray as $value) into the while loop?
>
>

Try:

$i = 0;
foreach ($myarray as $value) {
$index++;
print($index . ". ");
print($value);
$i++;
if ($i > 100) {
break;
}
}

Hope this helps,
Jrf

 

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

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