nested if else in php

Nested if else in php has slightly different syntax from c++. Here is an example:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>

</head>

<body>
<?php
$a=10;
$b=20;

if($a > $b)
{
  echo "a is greater than b";	
}
elseif($a == $b)
{
  echo "a is equal to b";
}
else
{
  echo "a is smaller than b";
}
?>
</body>
</html>

Looking carefully, we can see it is “elseif” rather than “else if” in php

Add a Comment

Your email address will not be published. Required fields are marked *