我有一些非常丑陋的代码,我需要帮助来清理它。我相信肯定有更好的方法。 我有一个$ _POST变量,条目start_doy0,start_doy1,start_doy2等虽然循环测试替代
后来的条目我没有填写,我需要找到他们填充什么doy。 我不能以$ completed_index = -1开始,因为没有start_doy-1。
#Assume at least one line full, index 0.
$completed_index = 0;
while (!empty($_POST['start_doy'.$completed_index]))
{
$completed_index++;
}
# $_POST['start_doy'.$completed_index] was empty, decrement $completed_index.
$completed_index--;
Thnks, 马特
如果至少索引0存在,就可以开始从1而不是0。 – palindrom
你''
如果用户完成start_doy0,start_doy2和start_doy3(但不是** start_doy1),则您的while循环会在到达start_doy2和start_doy3之前停止 - 因此您可能会错过任何东西。我不知道这是否相关...... :) – Tom