Solved

Restrict results in foreach loop

Posted on 2011-03-15
1
247 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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…

911 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

20 Experts available now in Live!

Get 1:1 Help Now