PHP IF ELSE


PHP Tutorial > IF ELSE

IF..ELSE is used in PHP to provide conditional judgements. The basic syntax is as follows:

IF (conditional statement) {
  [code if condition is true]
}
ELSE {
  [code if condition is false]
}

Let's see an example. Assuming we have the following piece of code:

$sample = 10;
IF ($sample > 5) {
  print "Number is greater than 5";
}
ELSE {
  print "Number is less than 5";
}

The output of the above code is:

Number is greater than 5

This is because the condition, ($sample > 5), is true. Therefore, the code in the bracket after IF is executed.

Next: PHP ELSEIF





Copyright 1keydata.com 2007, 2008, All Rights Reserved.   Privacy Policy



PHP Tutorial
PHP Variables
PHP Operators
PHP IF ELSE
PHP ELSEIF
PHP Switch
PHP While Loop
PHP FOR Loop
PHP DO WHILE Loop
PHP FOREACH Loop
PHP INCLUDE
PHP Functions
PHP ARRAY
PHP FORMS
PHP Cookies
PHP Redirect
PHP MySQL

PHP Commands

Resources