HOME C C++ PYTHON JAVA HTML CSS JAVASCRIPT BOOTSTRAP JQUERY REACT PHP SQL AJAX JSON DATA SCIENCE AI

PHP Nested if Statement


• Nested If

A nested if statement in PHP occurs when you place an if statement within the body of another if statement.

Example


An if inside an if:


<!DOCTYPE html>
<html>
<body>

<?php
$a = 13;

if ($a > 10) {
  echo "Above 10";
  if ($a > 20) {
    echo " and also above 20";
  } else {
    echo " but not above 20";
  }
}
?>

</body>
</html>

Output

Above 10 but not above 20