PHP if else statement

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

Notifications

Updates are enabled for this browser.

Receive new tutorials, articles and learning resources. You can turn updates off anytime.

Test browser code

Use this code in admin to send a test notification to this browser.