# Values Comparison using Dictionary Order and Numeric Order i

by anonymous

• 0
• 0
• 0
73 views
```Orignal Source:http://codingvilla.com/values-comparison-dictionary-order-php-single-article-594.aspx

Values Comparison using Dictionary order

In dictionary order the values are compared alphabetically. For example ‘a’ has index/position ‘1’ in alphabets ‘b’ has index/position ‘2’ so  ‘b’ is greater than ‘a’ .

Code:

<?php

if ('a' < 'z') {
echo  "a is less than z";
} else {
echo "a is not less than z";
}
echo "<br/>";
?>

Output:

a is less than z

Explanation

In the above code we have checked whether ‘a’ is less than z or not. The index/position of ‘a’ =‘1’ less than index/position of ‘z’= ‘26’.  The output is “a is less than z”.

Code:

<?php

if ('7q' < '45b') {
echo  "7q is less than 45b";
} else {
echo "7q is not less than 45b";
}
echo "<br/>";
?>

Output:

7q is not less than 45b

Explanation

As we know Strings are checked by dictionary order. In the above example we check the index/position of alphabet in the string whatever number we have in the string. According to the string alphabetic index/position it is greater and less.

Code:

<?php

if ('q7' < 'b45') {
echo  "q7 is less than b45";
} else {
echo "q7 is not less than b45";
}
echo "<br/>";
?>

Output:

q7 is not less than b45

Explanation

As we know Strings are checked by dictionary order. In the above example we have checked the index of the alphabet in the string whatever number we have in the string. According to the string alphabetic index it is greater or less.

Values Comparison using Numerical order

In Numerical order values are compared in number form like 3 is greater than 2.6 is greater than 5 etc.

In numerical order the index/position of number is checked.

Code:

<?php

if ('76z' < 56) {
print " 76z is less than the number 56.";
} else {
print " 76z is not less than the number 56.";
}
?>

Output:

76z is not less than the number 56.

Explanation:

In numerical order we have checked the position of the number. In the above example we have checked the string 76z is less than 56 that is integer so the process is firstly we have to check the position of the number in string than decide as we know 76 is greater than 56 then result is” 76z which is not less than the number 56 “.

Code:

<?php

if ('45a' < 85) {
print " 45a is less than the number 85.";
} else {
print " 45a is not less than the number 85.";
}
echo "<br/>";

?>

Output:

45a is less than the number 85.

Explanation:

In numerical order we have checked the position of the number. In the above example we have checked the string 45a is less than 85.As we know 45 is less than 85 in numbers. The output is 45a is less than the number 85.```