我已經用goto
命令編寫了一個腳本,但是在我想執行腳本的服務器上有一個以前的PHP版本(< 5.3),所以我必須更改代碼。代碼的結構是這樣的:php中的goto循環問題
for($i = 0; $i < 30; $i++) // print 30 articles
{
$x = 0;
// choose a a feed from the db
// parse it
a:
foreach($feed->get_items($x, 1) as $item)
{
// create a unique id for the article of the feed
if($id == $dbid)
{
// if this id exists in the db, take the next article of the same feed which is not in the db
$x++;
goto a;
}
else
{
// print the original article you grabbed
}
} // end of foreach
} // end of for
我已經測試了一切。你有什麼想法,我怎麼能不用goto
轉換這個代碼,以便正確執行?
不得不刪除我的第一個答案原來的代碼是後編輯 – james 2011-06-04 16:51:57
這就是爲什麼GOTO是邪惡的。 IT總是很難確定工作流程 – dynamic 2011-06-04 16:52:13
@ yes123:強制性的:http://xkcd.com/292/ – damianb 2011-06-04 16:56:00