1. Computing & Technology

Discuss in my forum

Using Comparison Operators in PHP

By , About.com Guide

You can use PHP code to compare two numbers and then make a decision based on if the condition is true or false. Here are the comparisons that you can use:

> (greater than)
< (less than)
== (equal to)
!= (not equal to)
<= (Less Than or Equal To)
>= (Greater Than or Equal To)

Here is an example of how to use an operator to make a decision in combination with the if () function.

<?php
if ($x > $y)
{
echo "x is greater than y";
}
elseif ($x == $y)
{
echo "x is equal to y";
}
else
{
echo "x is smaller than y";
}
?>

©2012 About.com. All rights reserved.

A part of The New York Times Company.