我有一個foreach循環,我需要編號類,所以我成立了一個計數器:計數器在foreach循環不工作
<?php
$counter = 0;
?>
<?php
$html = '';
foreach ($json['feed']['entries'] as $entries){
$counter++;
$html .= '<a href="' .$entries['link']. '"><span class="feeddisplay_title">'.$entries['title']. ' </span></a>';
if($entries['publishedDate'] != '') {
$html .='<span class="feeddisplay_date">' .$entries['publishedDate']. '</span>';
}
$html .= '<p>' .$entries['contentSnippet']. '</p>';
}
?>
<div class="box feed-<?php echo $counter; ?>">
<div class="box-heading"><?php echo $heading_title; ?>:</div>
<div class="box-content">
<div class="feeddisplay"><?php echo $html ?></div>
</div>
</div>
而且我的輸出類是「飼料-1」一遍又一遍。它不上漲。我嘗試了一些變化,我卡住了。