PHP Else Statement

by Hiroshi on June 20, 2008

in Else, PHP Basics

To understand else statement consider following example.

<?php
$apples="2";
if($apples=='3')
{
echo "Wrong";
}
else
{
echo "Correct";
}
?>

The output will be correct because apples are not 3. These are 2. This example is about if apples are 3 then print wrong otherwise print correct. We have a variables of apples set to 2. So output is correct.

Another example

<?php
$number = "5";
if ($number < 10)
{
  echo "$number is less than ten";
}
else
{
  echo "$number is greater than ten";
}
// output: 5 is less than ten
?>

Related Posts

Previous post:

Next post: