我正在使用此代码并且它有效。事实是我不知道如何在没有 goto 的情况下更有效地重写它。我个人认为在这种情况下使用 goto (php 中的新功能)是可以的,但其他人告诉我这不行。我应该如何在没有 goto 的情况下重写我的代码?为什么你认为我的代码在 goto 方面不好?我不是经验丰富的程序员,所以任何我做错了什么的建议都值得赞赏。
check_process:
$random_code = substr(number_format(time() * rand(),0,'',''),0,10);
$unique_check = $wpdb->get_var(
"SELECT meta_id
FROM {$wpdb->postmeta}
WHERE meta_key = 'unique_code'
AND meta_value = '{$random_code}'
LIMIT 1"
);
if ($unique_check == NULL) {
// OK
}
else {
goto check_process; // go back and generate another unique code if are same
}