|
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]
|