What ‘Control Structures’ are available through PHP and how do they work?
Print Email
Email this article
Close
Email this article
CloseYou are here: Home > Website Support > PHP
PHP provides most basic control structures seen in other languages, among them the looping constructs for and while, and the standard if/else construct. Examples are given below:
// for Loop Example
for ($i = 0; $i <= 10; $i++) {
echo "Current Iteration: $i\n";
}
// while Loop Example
$i = 0;
while ($i <= 10) {
echo "Current Iteration: $i\n";
$i++;
}
// if/elseif/else Example
if ($i >20) {
echo "$i is greater than 20.\n";
} elseif ($i >10) {
echo "$i is greater than 10.\n";
} else {
echo "$i is less than 10.\n";
}
?>
Was this information helpful?
Yes NoThank you for your feedback
We are delighted to find that our article resolved your query.
Thank you for your feedback
We will resolve your query as soon as possible.
Please take a few moments to comment on your unresolved query. Simply tell us what your problem is. We guarantee that we'll get back to you within two hours (during office hours) in response to your query.
