While loop on PHP Object?

dreamzdb

New member
I would like to use a for or while loop instead of foreach to iterate through this object but I can't seem to make it work. The code prints various properties of an event... I would like to use the for / while loop so that I can only print 3 events. The result of the first line is 5.

$num = count($eventObjList);
echo $num;
foreach($eventObjList as $ce) {
$date = $ce->getDateString();
list($day, $year, $time) = split('[,]', $date);
echo "<h3>";
echo $day . ', ' . $year . ' • ' . $time;
echo "</h3>";
echo '<p>';
echo '<a href="/events">' . $ce->getCollectionName() . '</a><br /> ';
if ($ce->getCollectionDescription() != '') {
echo $ce->getCollectionDescription();
}
echo '</p>';
}
 
Back
Top