当我需要检查array2是否有来自array1的某些值(随机生成)时,我遇到了这种情况。到目前为止,虽然我的
解决方法goto
redo : $id=mt_rand(0,count(array1));
foreach($array2 as $arr)
{
if($arr[0]==$id) goto redo;
}
//Some actions if randomly generated value from array1 wasn't found in array2
但我真的不喜欢使用goto语句。我敢肯定有一些简单的解决办法做到不跳转,但我不能把它d:
'do {$ id = mt_rand(...); $ contains =/*确定数组是否包含此id * /; } while($ contains);' – DCoder 2012-08-12 09:57:55
按照建议使用合适的结构('do-while'),并且记住... **绝对不要**和**从不**使用'goto'运算符。这是一个笑话。对于真实情况:请查看[PHP手册](http:// it。)底部的[漫画](http://it.php.net/manual/en/images/0baa1b9fae6aec55bbb73037f3016001-xkcd-goto.png)。 php.net/manual/en/control-structures.goto.php) – 2012-08-12 10:15:18
我看到了这张图片:P – 2012-08-12 10:42:50