Solved

Restrict results in foreach loop

Posted on 2011-03-15
1
273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

738 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