Re: Comparing Two Values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Andre Matos wrote:
> Hi List,
>
> I was comparing two values, a current value with a new value to build > the UPDATE instruction and I faced this:
>
> Current value: 2 == new value: 0002


in short, assuming that both the variables are not integers (i.e.
2 is equal to 0002) you should use === if you want '002' to not equal '2'.

try the following lines of code:

var_dump(2 === 002);
var_dump('2' === '002');
var_dump('2' == '002');
var_dump(2 == 002);
var_dump(2 == '002');

....amazing what a bit of experimentation can teach you....

>
> So, PHP is telling me that the current is equal to the new. Is this
> possible? Any idea to avoid this problem?

this is not a problem, its the documented behaviour, actually it's the foundation of what makes php so easy to use - namely automatic typecasting and dynamic types (I am probably not explaining that too well).

read the manual to understand more:

http://nl.php.net/manual/en/language.operators.comparison.php
http://nl.php.net/manual/en/language.types.string.php#language.types.string.conversion

BTW: this is not a DB question.  ;-)

>
> Thanks for any help.
>
> Andre
>
> --
> Andre Matos
> andre.matos@xxxxxxxxxxxx
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux