Breaking the nested loop [duplicate]

Unlike other languages such as C/C++, in PHP you can use the optional param of break like this:

break 2;

In this case if you have two loops such that:

while(...) {
   while(...) {
      // do
      // something

      break 2; // skip both
   }
}

break 2 will skip both while loops.

Doc: http://php.net/manual/en/control-structures.break.php

This makes jumping over nested loops more readable than for example using goto of other languages

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)