PHP if Keyword

❮ PHP Keywords

Example

Print a string if $a is less than five:

<?php
$a = 4;
if($a < 5) {
  echo "Less than five";
}
?>
Try it Yourself »

Definition and Usage

The if keyword is used to create an if conditional. The elseif and else keywords can be used to specify code that runs when the condition is not met.


Related Pages

The elseif keyword

The else keyword

Read more about conditionals in our PHP Conditionals Tutorial.


❮ PHP Keywords
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.