Michan Posted December 9, 2007 Share Posted December 9, 2007 Hi all, Say I have an array of ten results; how would I output the first five and no more? Thanks in advance. - Mi Link to comment https://forums.phpfreaks.com/topic/80862-limiting-amount-of-results-outputted-by-an-array/ Share on other sites More sharing options...
GingerRobot Posted December 9, 2007 Share Posted December 9, 2007 Kinda depends on the array. Assuming an array with keys 0,1,2,3,4,5 etc: for($i=0;$i<5;$i++){ echo $array[$i].'<br />'; } If you have other keys, you could try: $i=0; foreach($array as $v){ echo $v.'<br />'; if(++$i==5){ break; } } Link to comment https://forums.phpfreaks.com/topic/80862-limiting-amount-of-results-outputted-by-an-array/#findComment-410227 Share on other sites More sharing options...
Michan Posted December 9, 2007 Author Share Posted December 9, 2007 Thanks, the second snippet works very well! So how would I output results #6 - 10? Thank you in advance Link to comment https://forums.phpfreaks.com/topic/80862-limiting-amount-of-results-outputted-by-an-array/#findComment-410229 Share on other sites More sharing options...
Michan Posted December 9, 2007 Author Share Posted December 9, 2007 Hate to bump, but.. anyone? Link to comment https://forums.phpfreaks.com/topic/80862-limiting-amount-of-results-outputted-by-an-array/#findComment-410264 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.