# Logical Operators (Greater Than & Less Than) in PHP

by anonymous

• 0
• 0
• 0
80 views

Orignal Source:http://codingvilla.com/logical-operators-greater-than-less-than-php-single-article-596.aspx

Greater Than Operator

#### Code:

<?

\$var1 = 34;

\$var2 = 56;

echo "two variable  values are \$var1 && \$var2 check for greater ";

echo "<br/>";

if (\$var2 > \$var1) {

echo "greater value is \$var2";

} else {

echo "not greater ";

}

echo "<br/>";

?>

#### Output:

two variable values are 34 && 56 check for greater

greater value is 56

Explanation:

In the above example we have assign two values to two variables \$var1,\$var2 and also Print their actual values. Then Check with the help of greater operator which value is greater on line 6, if \$var2 is greater than \$var1 then print \$var2 is greater if not print not greater.

Less than operator

#### Code:

<?

\$var1 = 34;

\$var2 = 56;

echo "two variable  values are \$var1 && \$var2 check for less";

echo "<br/>";

if (\$var1 <\$var2) {

echo "less  value is \$var1";

} else {

echo "not less ";

}

echo "<br/>";

?>

#### Output:

two variable values are 34 && 56 check for greater

less value is 34

Explanation:

In the above example we have assign two values to two variables \$var1,\$var2. We have also printed their actual values. Then we have Checked by less operator which value is less on line 6, if \$var1 is less  than \$var2 then print \$var1 is less if not print not less.