Conditionals
- Braces are optional (for single-statement blocks).
If ... else
if (expr) {
statements;
}
elseif (expr) {
statements;
}
else {
statements;
}
if (expr):
statements;
elseif (expr):
statements;
else:
statements;
endif;
Switch statement
switch (expr) {
case VALUE:
statements;
break;
case VALUE:
statements;
break;
default:
statements;
break;
}
switch (expr):
case VALUE:
statements;
break;
default:
statements;
break;
endswitch;
- The case value can be an integer, a floating-point number, or a string.
- Add a break statement to the end of the last case as a precautionary measure, in case additional cases are added later.
Resources URL:
notes/php/resources
Sources URL:
notes/php/sources