I am curious why this is happening in PHP:
'78' == ' 78' // true
'78' == '78 ' // false
I know that it's much better to use strcmp or the least ===. I also know that when you compare numerical strings with == they are casted to numbers if possible. I also can accept that the leading space is ignored, so (int)' 78' is 78, and the answer is true in the first case, but I'm really confused why it's false in the second.
I thought that '78' is casted to 78 and '78 ' is casted to 78, too, so they are the same and the answer is true, but obviously, that's not the case.
Any help will be appreciated! Thank you very much in advance! :)
' 78'is considered "numerical string" and the space is ignored, but in'78 'it is taken into consideration.var_dump();and/orprint_r();on both and see what shows up. That might explain it in its own right.var_dumpcan't help here because PHP is converting it internally before the comparison. I asked some internals people who hang out in chat and they said it's not possible to see that from this end.