php tutorial - PHP Conditional Statements - php programming - learn php - php code - php script




  • Conditional statements are used in order to perform the different actions based on the different conditions.
  • Very frequently when are you are writing the code, you need to perform different actions for different conditions.
  • In PHP, we have to follow four conditional statements:
    • if statement
    • if...else statement
    • if...elseif....else statement
    • switch statement
  • if statement - use this statement to execute some code only if a specified condition is true
  • if...else statement - use this statement to execute some code if a condition is true and another code if the condition is false
  • if...elseif....else statement - use this statement to select one of several blocks of code to be executed
  • switch statement - use this statement to select one of many blocks of code to be executed

if Statement :

  • if expression is evaluated to a Boolean value.
  • If the expression evaluates to be TRUE, PHP will execute its statement.
 If Statement

Learn PHP - PHP tutorial - If Statement - PHP examples - PHP programs

php language Syntax :

if (condition) 
{
   condition statement is true;
}
click below button to copy the code. php tutorial - team

if...else Statement :

  • The ifelse expression executes some code if a condition is true, if condition is false PHP will execute the else statement.
 If Else Statement

Learn PHP - PHP tutorial - If Else Statement - PHP examples - PHP programs


php language Syntax :

if (condition) 
{
    condition statement is true;
} 
else 
{
    condition statement is false;
}
click below button to copy the code. php tutorial - team

if...elseif....else Statement :

  • The if....elseif...else statement executes different codes for more than two conditions.
 If Elseif Statement

Learn PHP - PHP tutorial - If Elseif Statement - PHP examples - PHP programs

php language Syntax :

if (condition) 
{
    condition statement is true;
} 
elseif (condition) 
{
    condition statement is true;
} 
else 
{
    condition statement is false;
}
click below button to copy the code. php tutorial - team

switch Statement :

  • The switch statement is used to perform different actions based on the different conditions.
  • The switch statement is used to select one of many blocks .
 Switch Statement

Learn PHP - PHP tutorial - Switch Statement - PHP examples - PHP programs

php language Syntax :

switch (n) {
    case label1:
        code to be executed if n=label1;
        break;
    case label2:
        code to be executed if n=label2;
        break;
    case label3:
        code to be executed if n=label3;
        break;
    ...
    default:
        code to be executed if n is different from all labels;
}
click below button to copy the code. php tutorial - team



Related Searches to php Conditional Statements

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.

×