I need to be able to loop through a PHP object about 25 times, but using a foreach with an iteration counter doesn't get the job done. Can someone advise please?
Things I've Tried
$i = 0;
foreach($items as $item){
if($i < 25){
//do code here
$i++;
}else{
break;
}
}
this successfully counts through 1-25 and break but my code does not execute it just stops completely.
and i've also tried using a for loop but again this doesn't work. So what i really want to know is if there is a way to loop through a PHP object X amount of times before breaking out of the loop and carrying on with my code.
The reason i need this is because if i use "foreach" without limiting it, it will go through about 300 times which is way too much.
foreach (array_slice($items, 0, 25) as $item) { ... })?