PHP If...Else

PHP Decision Making

The if , elseif ...else and switch statements are used to take decision based on the different condition.

You can use conditional statements in your code to make your decisions. PHP supports following three decision making statements:


  • if...else statement-use this statement if you want to execute a set of code when a condition is true and another if the condition is not true
  • elseif statement- is used with the if...else statement to execute aset of codeif oneof several condition are true
  • switch statement- is usedif you want to select oneofmany blocks of codeto beexecuted, usethe Switch statement. Theswitch statement is used to avoidlong blocksof if..elseif..else code.


The If...Else Statement

If you want to execute some code if a condition is true and another code if acondition is false , use the if....else statement.



The following example will output "Have a nice weekend!" if the current day is Friday, otherwise it will output "Have a nice day!":



© 2015-16 All Rights Reserved Tech9schools