Comparing numeric strings

Posted by Kiren Siva on Stack Overflow See other posts from Stack Overflow or by Kiren Siva
Published on 2013-11-01T09:28:41Z Indexed on 2013/11/01 9:54 UTC
Read the original article Hit count: 269

Filed under:

From the question PHP Type-Juggling and (strict) Greater/Lesser Than Comparisons

I know PHP interpret strings as numbers whenever it can.

"10" < "1a"  => 10 less than 1      expecting  false 
"1a" < "2"   => 1 less than 2       expecting  true
"10" > "2"   => 10 greater than 2   expecting  true

But in the case of "10" < "1a" php returns true.

I am not understanding the concept please help me to clarify it.

Edit:

But when I add "10" + "1a" it returns 11 that means php interprets "10" as 10 and "1a" as 1. Is that correct?

© Stack Overflow or respective owner

Related posts about php