腳本的第一部分獲取數組中的前4個值並將結果輸出爲列表。腳本的第二部分應該得到其餘的值,如5,6,10等,如果有的話,並將它們全部放在一個div中,但目前我的腳本的第二部分仍然抓住了所有的值該數組從第一個開始。如何忽略第一個4,然後使用foreach輸出其餘值PHP
這裏是我的腳本
$counter = 0;
foreach ($value as $category_topic)
if(++$counter <= 4){
$template_image = '<img src="'.$image_path.$category_topic['ImagePath'].DS.$category_topic['templateImage'].'" width="'.$category_topic['templimgwidth'].'" height="'.$category_topic['templimgheight'].'" alt="'.$category_topic['templateTitle'].'" title="'.$category_topic['templateTitle'].'">';
$template_link ='<a href="'.DST.$category_topic['ImagePath'].DS.$category_topic['referring_url'].'">'.$category_topic['templateTitle'].'</a>';
print<<<END
<li>
<ul>
<li>{$template_image}</li>
<li class="bot_link">{$template_link}</li>
</ul>
</li>
END;
}
print <<<END
</ul>
<div>
END;
foreach ($value as $category_topic)
if(++$counter > 4){
$template_link[++$counter] ='<a href="'.DST.$category_topic['ImagePath'].DS.$category_topic['referring_url'].'">'.$category_topic['templateTitle'].'</a>';
print<<<END
{$template_link}
END;
}
print <<<END
</div>
</div>
END;
甜美,像魔術一樣工作,感謝您的回答 – AlexB