我想以後通過XML這裏3員額回聲圖像的每個是我的代碼:PHP:你如何確定循環的每一次第N次迭代?
<?php
// URL of the XML feed.
$feed = 'test.xml';
// How many items do we want to display?
//$display = 3;
// Check our XML file exists
if(!file_exists($feed)) {
die('The XML file could not be found!');
}
// First, open the XML file.
$xml = simplexml_load_file($feed);
// Set the counter for counting how many items we've displayed.
$counter = 0;
// Start the loop to display each item.
foreach($xml->post as $post) {
echo '
<div style="float:left; width: 180px; margin-top:20px; margin-bottom:10px;">
image file</a> <div class="design-sample-txt">'. $post->author.'</div></div>
';
// Increase the counter by one.
$counter++;
// Check to display all the items we want to.
if($counter >= 3) {
echo 'image file';
}
//if($counter == $display) {
// Yes. End the loop.
// break;
//}
// No. Continue.
}
?>
這裏是一個樣本前3個是正確的,但現在它不循環idgc.ca/web-design-samples -testing.php
請使用StackOverflow代碼格式化模式。您的代碼現在不可讀。 – 2009-06-01 19:10:37
問題是什麼? 還可以看看在文本區中可用的格式化工具.. – 2009-06-01 19:11:01