CKTIS / PHP
Keyword continue
Skip the rest of the current loop iteration.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
continue 2;Skip the rest of the current loop iteration. A positive literal level counts loops and switches including the current structure. Targeting a switch acts like break at that level and emits E_WARNING since PHP 7.3. Inside a switch nested in a loop, continue alone acts like break and emits a warning, while continue 2 advances the enclosing loop. A for loop still runs its update expression.
$kept=[];
for ($i=0;$i<4;$i++) { switch($i){case 1: continue 2;} $kept[]=$i; }
echo json_encode($kept);
[0,2,3]
Examples
<?php
$kept=[];
for ($i=0;$i<4;$i++) { switch($i){case 1: continue 2;} $kept[]=$i; }
echo json_encode($kept);
Result
[0,2,3]