我已经用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