PHP If Elseif Else

PHP If Else Statement Previous Next PHP Switch Statement


PHP If Elseif Else Statement is used to select one of several blocks of code to be executed.

The if..elseif.else Statements

Syntax

if(condition){ code to be executed if condition is true; }elseif(condition){ code to be executed if condition is true; }else{ code to be executed if condition is false; }

Here is the code of if..elseif.else statement.

Filename: php / else-if-statment.php


Code
<?php
// PHP if...else statement
$x=10;
$y="20";
if($x > $y){
 echo "$x is greater than $y";
}elseif($x==$y){
 echo "$x is equal to $y";
}else{
  echo "$y is greater than $x";
}
?>

Running Step.


Type Url - https://localhost/php/else-if-statment.php


Tags: PHP


Was this helpful ?

Related Code


Popular Code

Latest Code