if else in PHP
Advertisements
if else in PHP
In php if else statement is used to test condition. If conditon is true execute the code other wise control goes outside.
PHP If Statement
PHP if statement is executed if condition is true.
Syntax
if(condition) { //code to be executed }
if Statement Example in PHP
<?php $age=20; if($age<18) { echo "$You are Adult"; } ?>
Output
You are Adult
PHP If-else Statement
PHP if-else statement is executed whether condition is true or false.
Syntax
if(condition) { //code to be executed if true } else { //code to be executed if false }
if else Example in PHP
<?php $num=10; if($num%2==0) { echo "$num is even number"; } else { echo "$num is odd number"; } ?>
Output
10 is even number
Google Advertisment