Sunday 15 December 2013

if else in PHP example

If condition always run when condition is true e.g  if(true){} 
Example No.1
<?php
$true = true;
$false = false;

if($true == true)
{
 echo "This is true";
}else
{
     echo "This is flase";
}

?>
ouput:
This is true


Example No.2
<?php
$true = true;
$false = false;

if($true == $false)
{
 echo "I like mango";
}else
{
     echo "I like appple";
}

?>
ouput:
I like appple

Example No.3

<?php
$true = true;
$false = false;

if($true!== $false)
{
 echo "I like mango";
}else
{
     echo "I like appple";
}

?>
ouput:
I like mango

Example No.4
Using string comparison
 

<?php
$string1 = "BMW";
$string2 = "BMW";

if($string1 == $string2)
{
 echo $string1." ".$string2;
}else
{
     echo "It is else";
}

?>
ouput:
BMW BMW















No comments:

Post a Comment