07 January 2011

Php For Beginners (Lesson 4c)

In this lesson i will be discussing comparison operators and their applications in php.

== Operator

"==" operator is used for comparing two values or variables and return true if they are same.
<?php
$a=5;
if ($a==5)
   echo "Five";  //Outputs Five
?>
!= and <> Operator

"!=" and "<>" operators are also used for comparing two values or variables but they return true if the values are not same.
<?php
$a=5;
if ($a!=4)
   echo "Four";  //Outputs Four
if ($a<>4)
   echo "Four";  //Outputs Four
?>
> Operator

">" operator is used to check whether the first value is greater than second or not.
<?php
$a=5;
if ($a>4)
   echo "Greater";  //Outputs Greater 
?>
< Operator

"<" operator is used to check whether the first value is less than second or not.
<?php
$a=5;
if ($a<6)
   echo "Lesser";  //Outputs Lesser 
?>
>= Operator

">=" operator is used to check whether the first value is greater than or equal to the second value or not.
<?php
$a=5;
if ($a>=5)
   echo "Greater";  //Outputs Greater 
if ($a>=4)
   echo "Greater";  //Outputs Greater 
?>
<= Operator

"<=" operator is used to check whether the first value is less than or equal to the second value or not.
<?php
$a=5;
if ($a<=5)
   echo "Lesser";  //Outputs Lesser 
if ($a<=6)
   echo "Lesser";  //Outputs Lesser 
?>

Ok Guyz, that is all for this lesson, feel free to comment and ask any quries that you may have.


next Previous Lesson --- Next Lesson next

No comments: