skip current iteration

前端 未结 4 1192
醉话见心
醉话见心 2020-12-28 11:44

I have a php array $numbers = array(1,2,3,4,5,6,7,8,9)

if I am looping over it using a foreach foreach($numbers as $number)

and hav

4条回答
  •  梦毁少年i
    2020-12-28 12:11

    Break; will stop the loop and make compiler out side the loop. while continue; will just skip current one and go to next cycle. like:

    $i = 0;
    while ($i++)
    {
        if ($i == 3)
        {
            continue;
        }
        if ($i == 5)
        {
            break;
        }
        echo $i . "\n";
    }
    

    Output:

    1
    2
    4
    6 <- this won't happen
    

提交回复
热议问题