Re: Comparing Two Values

From: Date: Wed, 22 Dec 2004 01:52:05 +0000
Subject: Re: Comparing Two Values
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-37781@lists.php.net to get a copy of this message
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@sympatico.ca


« previous php.db (#37781) next »