Solved

Restrict results in foreach loop

Posted on 2011-03-15
1
237 Views
Last Modified: 2012-05-11
Hi all,

I have this code:

foreach ($val as $key=>$fval) {
            
        echo 'show data here';
        echo etc...
}

Now this code is showing all the results ...

How can I get it to show only 5 or 6 etc?

Basically I want to control how many results are displayed.

Can someone help please?

Thanks


0
Comment
Question by:error77
1 Comment
 
LVL 12

Accepted Solution

by:
enachemc earned 500 total points
ID: 35136423

$i  = 0;
foreach ($val as $key=>$fval) {
           
        echo 'show data here';
        echo etc...
       
$i+=1;
if($i > 6)break;
}
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now