Checking lest entry in a foreach

2 posts by 2 authors in: Forums > CMS Builder
Last Post: June 1, 2009   (RSS)

Re: [willbegood] Checking lest entry in a foreach

By Dave - June 1, 2009

Hi willbegood,

Try this:

<?php $totalRecords = count($newsRecords); ?>
<?php $count = 0; ?>

<?php foreach ($newsRecords as $record): ?>
Record Number: <?php echo $record['num'] ?><br/>
title: <?php echo $record['title'] ?><br/>
description: <?php echo $record['description'] ?><br/>

<?php if (++$count == $totalRecords): ?>
This is the last record.<br/>
<?php endif ?>


<hr/>
<?php endforeach; ?>


The new code is in red. Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com