Restrict results in foreach loop

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?


Who is Participating?
enachemcConnect With a Mentor Commented:

$i  = 0;
foreach ($val as $key=>$fval) {
        echo 'show data here';
        echo etc...
if($i > 6)break;
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.