PHP Operators : Using Comparison Operators

To compare php variables to determine whether they are the same or different.. you can use PHP Comparison Operators. See below for a list of examples..

I. Define the Variables

<?php
$num1 = 9;
$num2 = 9;
$num3 = 22;
?>

A. The Less Than Operator

<?php
//Returns true if variable in the left side is less than the right..
$res = ($num1 < $num3);
//returns true..
?>

B. The Greater Than Operator

<?php
//Returns true if the variable in left side is greater that the right..
$res = ($num3 > $num1);
//returns true..
?>

C. The Less Than or Equal-to Operator

<?php
//returns true if variable on left is less than or equal to right..
$res = ($num3 <= $num1);
//returns false
?>

D. The Greater Than or Equal-to Operator

<?php
//returns true if variable on left is greater than or equal to right..
$res = ($num3 >= $num2);
//returns true..
?>

E. The Equality Operator

<?php
//returns true if both variables are equal to each other
$res = ($num1 == $num2);
//returns true..
?>

F. The Not Equal-to Operator

<?php
//returns true if the variable on left is not equal to right
$res = ($num1 != $num2);
//returns false..
?>

G. The Inequality Operator

<?php
//returns true if the variable on left is not equal to right..
$res = ($num1 <> $num2);
//returns false..
?>
Share and Bookmark this Post..

  • Digg
  • Yahoo! Buzz
  • Twitter
  • Facebook
  • StumbleUpon
  • del.icio.us
  • Google Bookmarks
  • Technorati
  • Reddit
  • Sphinn
  • MySpace
  • Slashdot
  • BlinkList
  • Live
  • Mixx
  • NewsVine
  • Yahoo! Bookmarks
  • Ratimarks
  • LinkedIn





Tags: ,

6 Responses to “PHP Operators : Using Comparison Operators”







Leave a Reply

This blog will make your link do follow after you leave 5 comments. i check every comment posted and reply to each also. please do not spam i hate spam, there is no room for spam here in my blog thanks!

CommentLuv Enabled
:argh: :| :$ :B :cool: :*( :curious: x_x :gasp: =D :happy: :/ :D :injured: :lol: :lol2: :love: :X :meh: O_o :ohhyeahh: D: :omg: :raisebrow: :P :( 0_0 :shocked: :sly: :) :] ;] :worry: :wow:

Subscribe to feed

this blog use Comment Luv

Featured Post


Make your Wordpress URL Search Engine Friendly
Simple steps to make your wordpress url search engine friendly..


Give some luv with comment luv
This blog is now comment luv powered..


Fix Wordpress PHP fatal error memory size exhauster
Ways on how to solve PHP fatal error or PHP memory limit on wordpress blogs anr other opensource web apps..


Download Norton Antivirus Internet Security for free
Read this post to know how you can download a free norton antivirus or internet security..


Sponsored Links


 9 Users Online