如何限制这个循环..调整你的循环…帮助
<?PHP foreach($section['Article'] as $article) : ?> <tr> <td> <?PHP if ($article['status'] == 1) { echo $article['title']; } ?> </td> <td> <?PHP if($article['status']== 1) { echo ' '.$html->link('View','/articles/view/'.$article['id']); } ?> </td> </tr> <?PHP endforeach; ?>
首先,准备你的数据
原文链接:https://www.f2er.com/php/131564.html$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;
然后显示它
<?PHP foreach($section['Article'] as $article ): ?> <tr> <td><?PHP echo $article['title'] ?></td> <td> <?PHP echo $article['link']?></td> </tr> <?PHP endforeach ?>