Sunday, March 14, 2010

PHP - If...Else

In PHP, there are several conditional statements that you must understand first:
  • if statement - used to execute some code if a specified condition is TRUE.
  • if...else statement - used to execute some code if a condition is TRUE, and used another code if the condition is FALSE.
  • if...else if...else statement - used to select one of the blocks of code to be executed.
  • switch statement - used to select one of many blocks of code to be executed.

If...
Statement


The following example will output "Happy New Year!" if the current year is 2020:




If...else
Statement


The following example will output "Happy New Year!" if the current year is 2020, otherwise it will output "Enjoy your day!":


Or you can try this one:



If...elseif...else Statement

The following example will output "Happy New Year!" if the current year is 2020, and "Welcome Year 2021!" if the current year is 2021. Otherwise it will output "See You Again Next Year!":

0 comments:

Post a Comment