Decision Making statements in PHP :

When we want to take decision on different condition at this time we use the decision making statements. In PHP there are following conditional statements are use:

  • if statement
  • if…….else statement
  • if…..elseif……else statement
  • switch statement

if statement:

if statement in PHP is use to execute some code only if the specified condition is true.

Syntax:

 Example:

if…..else statement:

if….else statement in PHP is use to execute code when the if condition is true otherwise the else condition will executed.

Syntax:

 Example:

 

if…elseif……else statement:

if….elseif…else statement in PHP is use to execute code when the if condition is true if the condition is false than it will check the elseif condition and if it is true than the elseif code will executed otherwise the else condition is execute.

Syntax:

 Example:

Switch Statement:

If there are so many conditions that you have to check at this time you can use “if…elseif….else” statement but it will be more complicated if there are so many blocks. So if you want to execute many blocks than use “switch statement”.

Syntax:

 Example:

In following example we are executing one block with the condition:

Example:

In following example we are executing default condition means the labels are not matching any condition:

One response to “Decision Making Statements in PHP”

  1. Stanley Chamorro says:

    I was just seeking this information for a while. After 6 hours of continuous Googleing, at last I got it in your web site. I wonder what’s the Google’s issue that doesn’t rank this kind of informative websites closer to the top. Normally the top sites are full of garbage.

Leave a Reply

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