what are Different Control Statements in PHP

Follow by Email
Facebook0
Facebook
Google+
https://codingsec.net/2016/11/different-control-statements-php/

Control statements in PHP are used to control the flow of execution in a script. There are three categories of control statements in PHP: selection statements, iteration / loop statements and jump statements.

 

Selection statements

The selection statements in PHP allows the PHP processor to select a set of statements based on the truth value of a condition or Boolean expression. Selection statements in PHP are if, if-else, elseif ladder and switch statement.

Syntax of if is given below:

Syntax of if-else is given below:

Syntax of elseif ladder is given below:

Syntax of switch statement is shown below:

The labels for case statements can be either an integer, double or a string. The default block is optional. If the break statement is absent, the following cases will also execute until a break statement is found.

 

Iteration or Loop Statements

The iteration statements in PHP allows PHP processor to iterate over or repeat a set of statements for a finite or infinite times. Iteration statements supported by PHP are while, do-while, for and foreach.

Syntax of while loop is given below:

Syntax of do-while loop is given below:

Syntax of for loop is given below:

The foreach loop is used to iterate over array elements and its syntax is given below:

 

Jump Statements

The jump statements available in PHP are break and continue. The break statement is used to break the control from a loop, take it to the next statement after the loop  and continue is used to skip the control from current line to the next iteration of the loop.

Take your time to comment on this article.

Follow by Email
Facebook0
Facebook
Google+
https://codingsec.net/2016/11/different-control-statements-php/

Add a Comment

Your email address will not be published. Required fields are marked *

Like the article? please consider sharing it. Thank you

Advertisment ad adsense adlogger