PHP Syntax Statements Conditional else

 

- Info:

- else statement can be used only in combination with if statement.

- If condition specified by if statement is TRUE then only code defined in if statement is executed.

If condition specified by if statement is FALSE then only code defined in else statement is executed.

- If code belonging to if or else statements contains only single statement, curly brackets can be ommited.

This is not recomended since it makes code less readable and adding additional code statements can lead to errors.

 

- Syntax:

if (condition) { code1 }

else { code2 }

 

- Example:

- Creat PHP Console Application Test.php.

 

Test.php

<?php

 

$number = 10;

if ($number == 10 ) { print "Number is 10"; }

else { print "Number is not 10"; }

 

?>