Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use flow Control statement and Loop Control statement based on php

Shulou Source: shulou.com Published: 2022-06-03 18:04:21 09月30日 Update

This article will explain in detail how to use php-based process control statements and loop control statements. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

1. There are mainly four kinds of process control statements: if, ii...else, elseif (sometimes it can be written as elseif) and switch.

The format of the statement in PHP is:

If (condition satisfied) {execute statement}

If (condition satisfied) {execute statement} else {execute statement}

If (condition satisfied) {execution statement} elseif {execution statement} elseif {execution statement}. Else {execute statement}

Switch (conditional) {case 1: statement; break

Case 2: statement; break

Case 3: statement; break

Default: statement; break;}

If: there is only one condition

If...else: there are two conditions

Elseif: there are multiple conditions

Switch: multiple conditions when multiple conditions, elseif and switch statements have the same effect. However, in order to avoid complicated and lengthy sentences, use the switch statement

2. There are mainly three kinds of loop control statements: while, for and do while. For example, output all integers less than 5.

The format of the statement in PHP is:

* while statement *

I = 0; while ($I

Tags: Statement loop condition control multiple flow parenthesis format article form more number of times yes lengthy complex practical same complicated for this reason code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL macOS Docker OPPO Reno Microsoft