how to limit foreach loop to three loops
This will help if your array is numerically indexed
foreach($section['Article'] as $i => $article ):
if ($i > 3) break;
Otherwise - manually increment the counter:
$i = 0;
foreach($section['Article'] as $article ):
if ($i++ > 3) break;
first, prepare your data
$i = 1;
$data = array();
foreach($section['Article'] as $article ) {
if($article['status']== 1) {
$article['link'] = $html->link('View', '/articles/view/'.$article['id']);
$data[] = $article;
if ($i++ == 3) break;
}
}
$section['Article'] = $data;
then display it
<?php foreach($section['Article'] as $article ): ?>
<tr>
<td><?php echo $article['title'] ?></td>
<td> <?php echo $article['link']?></td>
</tr>
<?php endforeach ?>
Slice the array.
foreach(array_slice($section['Article'], 0, 3) as $article ):