http://www.php.net/manual/en/language.operators.comparison.php
If you compare a number with a string or the comparison involves numerical strings,
then each string is converted to a number
and the comparison performed numerically.
These rules also apply to the 'switch' statement.
What I can see there is no way to compare 2 strings with numeric characters as strings.
Not when using regular <, >, >=, <= comparison operators.
The number 561 is not the same as the string "561".
And "2341" is less than "561", because '2' comes before '5' in ASCII
Consider the test in script below.
First case compares 2 strings with char 'a' at the end.
The Result is as expected.
Second case has the char '1' at the end making the string all numeric.
Only the special string compare function [man]strcmp[/man]
delivers expected result.
Question:
Is there some trick or workaround to be able to compare numerical strings
using the regular comparison operators?
Something that would make those strings be treated as strings.
<?php
echo '<pre>';
$a = "56a";
$b = "234a";
var_dump($a < $b);
var_dump((string)$a < (string)$b);
var_dump(strcmp($a,$b) < 0);
/* Result:
false
false
false */
echo '<hr />';
$a = "561";
$b = "2341";
var_dump($a < $b);
var_dump((string)$a < (string)$b);
var_dump(strcmp($a,$b) < 0);
/* Result:
true
true
false */
?>