PHP IF Statement

  • if statement -  It is used to execute an instruction or Block of instructions only if a condition is fulfilled.
The Syntax is as follows :
     
      if(condition)
           statement;

Where condition is the expression that is to be evaluated. If this condition is true statement is executed. If it is false  statement is ignored and the program continues on the next instruction after the conditional statement.

if we want more than one statement to be execute then we can specify a block of statement within the curly bracers { }.

The Syntax is as follows :

     if(condition)
       {
           block of statements;
       }

Example : 
      Program to calculate the net salary of an employee..

<?php

   $gross_salary = 1000;
   $net_salary=0;

   if($gross_salary < 10000) 
           net_salary = gross_salary; 
   if($gross_salary >= 10000)
         net_salary=gross_salary - 0.15 * gross_salary;

echo "<br/> Net Salary is Rs- $net_salary ";

?>


Comments