PHP if statement is used to execute some code, if a condition is evaluated to true otherwise if the condition is evaluated to false, execute nothing, or execute some other code.



Figure - Flowchart of if Statement:

php-if-else

The following example will output "wish you a very happy birthday" if the current date is 01-10. Otherwise, it will output nothing. You can also use only if condition, if else is not required.

Example of a PHP Program to Demonstrate if Statement

Example:

<?php 
$date=date("m-d"); 

if ($date=="01-10") { 
  echo "Wishing you a very Happy Birthday"; 
}
else{
  //nothing
}
?> 


Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram