PHP endif Keyword

PHP Keywords : End an if conditional

Definition and Usage

The endif keyword is used to mark the end of an if conditional which was started with the if(...): syntax. It also applies to any variation of the if conditional, such as if...elseif and if...else.

Related Pages

The if keyword.

The else keyword.

The elseif keyword.

Read more about conditional statements in our PHP if else Tutorial.

More Examples

Example

End an if...else conditional:

<?php
$a = 4;
if($a < 5):
  echo "Less than five";
else:
  echo "Greater than five";
endif;
?>

Example

End an if...elseif...else conditional:

<?php
$a = 4;
if($a < 5):
  echo "Less than five";
elseif($a < 10):
  echo "More than five but less than ten";
else:
  echo "Greater than ten";
endif;
?>

❮ PHP Keywords