Difference between break and continue in PHP?

后端 未结 10 2443
粉色の甜心
粉色の甜心 2020-12-02 05:02

What is the difference between break and continue in PHP?

10条回答
  •  醉梦人生
    2020-12-02 05:47

    break used to get out from the loop statement, but continue just stop script on specific condition and then continue looping statement until reach the end..

    for($i=0; $i<10; $i++){
        if($i == 5){
            echo "It reach five
    "; continue; } echo $i . "
    "; } echo "
    "; for($i=0; $i<10; $i++){ if($i == 5){ echo "It reach end
    "; break; } echo $i . "
    "; }

    Hope it can help u;

提交回复
热议问题