Advanced Java and Web Technologies for JNTUK
Blog providing beginner tutorials on different web technologies like HTML, CSS, Javascript, PHP, MYSQL, XML, Java Beans, Servlets, JSP and AJAX

09/03/2015 Categories: PHP. No Comments on Control Statements in 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.

Suryateja Pericherla

Suryateja Pericherla

Hello, I am Suryateja Pericherla working as an Asst. Professor in CSE department at Vishnu Institute of Technology. I write articles to share my knowledge and make people knowledgeable regarding certain topics.
Suryateja Pericherla

Latest posts by Suryateja Pericherla (see all)

Note: Do you have a question on this article or have a suggestion to make this article better? You can ask or suggest us by filling in the below form. After commenting, your comment will be held for moderation and will be published in 24-48 hrs.

Leave a Reply

Scroll Up
Thank you for visiting! If you like this website do share with your friends by clicking on the social icons available on the left hand side.

As the domain name is quite large to remember, use this short domain to visit this site. Short domain: