PHP Expression: Why var_dump(false < -1) = true?

120 Views Asked by At

Can you please explain how PHP execute this code and the result is true?

var_dump( (false < -1) ); //bool(true)
2

There are 2 best solutions below

5
On

False is boolean type, and from PHP maunal:

-1 is considered TRUE, like any other non-zero (whether negative or positive) number!

Resource: http://php.net/bool

1
On

For comparison PHP is casting values to same types.

If -1 is casted to boolen, that is true, so if you compare false < true then true is correct value.