How to do control structures in PHP?
IF statement.
if (condition)
{
Statement(s);
}
Or
if (condition)
{
Statement(s);
} else
{
Statement(s);
}
Or
if (condition)
{
Statement(s);
} elseif (condition)
{
Statement(s);
}
The Switch Conditional:
switch ($variable) {
case “value”:
statement(s);
break;
case “value”:
statement(s);
break;
default
statement(s);
break;
}
The loop condition:
for (initial expression; condition; closing expression) {
statement(s);
}
while (condition) {
statement(s);
}
do {
statement(s);
} while (condition);
foreach ($array) {
statement(s);
}
|