0

I am trying to evaluate an expression which is as follows:

if($x != $y)

Suppose the values of $x is 4 and $y is 14 then the result is true.
But if the values of $x is 4 and $y is 04 then the result is false.
Why this is so?

Anshu Mishra
  • 361
  • 1
  • 7
  • 18
  • When you compare `4` to `'04'` PHP type juggles the string to an integer value, which is 4, so they are the same. – Nick Nov 08 '19 at 07:15
  • [Some test](http://sandbox.onlinephpfunctions.com/code/fd68bfa15ae42a48b06c474606ceb4d9dacd4957) – Aksen P Nov 08 '19 at 07:17
  • @AksenP Yes, I am getting the same result. i want to know why is it happening in this way. And what is the woraround for this. Because in my case if 4 != 04 should be true. – Anshu Mishra Nov 08 '19 at 07:30

0 Answers0