PHP control flow

ControlFlow PHP Programming Reference

Loops


if (EXPR) STATEMENT elseif (EXPR) STATEMENT else STATEMENT

while (EXPR) STATEMENT

do BLOCK while (EXPR)

for (EXPR; EXPR; EXPR) STATEMENT

foreach (ARRAY as $key => $value) STATEMENT
foreach (ARRAY as list(...)) STATEMENT

switch (EXPR) case VALUE: STATEMENT+ default: STATEMENT+

try BLOCK catch (TYPE $var) BLOCK finally BLOCK

Loop control


continue LEVELS   # go to next iteration
break    LEVELS   # exit loop

Alternative syntax


if (EXPR): STATEMENT+ elseif (EXPR): STATEMENT+ else: STATEMENT+ endif

while (EXPR): STATEMENT+ endwhile

for (EXPR; EXPR; EXPR): STATEMENT+ endfor

foreach ... endforeach

switch ... endswitch

Notes

Links