dongwei4096 2013-01-21 13:48
浏览 8
已采纳

在同一个foreachloop中休息并继续[关闭]

is it possible to have 2 conditions in the same foreach loop with one which continues, and one which breaks. so I want to find all full input fields and make them $$key, but make only the first empty input field $_POST['email']. can I do this in the same loop or do I nee 2 loops? here is an example, this doesn't work, it breaks.

foreach( $_POST as $key=> $for ) {
    if ( $for!='') {
        $$key = $for;   continue;
    } else if ( $for=='') { 
        $$key = $_POST['email'];  break;
    }
  • 写回答

2条回答 默认 最新

  • dream_high1026 2013-01-21 13:53
    关注

    Your example code doesn't make a lot of sense: if ($for!=''), then the only other thing which can possibly be is $for=='', therefore the second if clause is redundant. Further, what are you tring to achive by setting the result in $$key - there may be a reason for this but it is not shown in the code you've published.

    Yes, it's quite possible to have multiple break and continue constructs inside a loop. And they will work properly.

    However it would be much more efficient to implement your code as simply:

    $email=$_POST['email'];
    

    (although this also removes a lot side-effects and potential vulnerabilities from the code).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大