Jump to content

Limiting amount of results outputted by an array


Michan

Recommended Posts

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;
}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.