IF and ELSE condition in PHP

We learnt about variables in previous post now we will learn about condition IF and ELSE This condition is used when we want code to perform particular action based on condition. For Example in below program Line 1 : Assigns the value to variable $apples.
Line 2 : Assigns the value to variable $bananas .
Line 3 : This statement does the total of two values assigned to both variables $apples , $bananas
  1. $apples = '100' ;
  2. $bananas = '50' ;
  3. $total = $apples + $bananas ;
  4. // Total will be 150 simple math, you can check the value using echo $total
  5. //echo $total // Un-comment this statement to check the value of $total by removing '//' from beginning of this statement
  6. if($total > 100) // This statement will check the value assigned to $total is greater than 100 if yes it will perform the action written between { "Perform this action" } if value is not grater than 100 it will ignore the brackets after if {""} and will perform the action written in brackets written after else
  7. {
  8. echo "Too Expensive" ;
  9. }
  10. else
  11. {
  12. echo "Low Cost" ;
  13. }

If You Think This Post has helped you buy us a Coffee :)

Make Donation

  • Other: $

Donate now