RE: [PHP-DB] Comparing Two Values

2004-12-22 Thread Andre Matos
It is working now using === or !==

Thanks a lot.

Andre

--
Andre Matos
[EMAIL PROTECTED] 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, December 21, 2004 8:10 PM
To: php-db@lists.php.net
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] Comparing Two Values

To be honest, I havn't had much use for it myself but I've done a lot of
'hack' projects that didn't need to be this specific.  But as I understand,
you might want to use the triple-equal sign to determine if they're exactly
the same.

Are you comparing...

2

with...

0002

(integer versus a string?)

If so, the === should work I believe.  It should compare variable types as
well as values so it shouldn't convert 0002 to just 2 before doing the
evaluation.

Good luck!

-TG

= = = Original message = = =

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

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

Thanks for any help.

Andre

--
Andre Matos
[EMAIL PROTECTED] 

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


___
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

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



Re: [PHP-DB] Comparing Two Values

2004-12-21 Thread tg-php
To be honest, I havn't had much use for it myself but I've done a lot of 'hack' 
projects that didn't need to be this specific.  But as I understand, you might 
want to use the triple-equal sign to determine if they're exactly the same.

Are you comparing...

2

with...

0002

(integer versus a string?)

If so, the === should work I believe.  It should compare variable types as well 
as values so it shouldn't convert 0002 to just 2 before doing the evaluation.

Good luck!

-TG

= = = Original message = = =

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

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

Thanks for any help.

Andre

--
Andre Matos
[EMAIL PROTECTED] 

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


___
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

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



Re: [PHP-DB] Comparing Two Values

2004-12-21 Thread Jochem Maas
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
 [EMAIL PROTECTED]

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


RE: [PHP-DB] Comparing Two Values

2004-12-21 Thread Bastien Koert
PHP implicitly casts the variables to be the same here...in this case the 
integer 2...if you want to force it to compare as text then you need to 
ensure that both variables are cast as text

see here (http://ca3.php.net/language.types.type-juggling )
bastien

From: Andre Matos [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Comparing Two Values
Date: Tue, 21 Dec 2004 18:21:26 -0500
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
So, PHP is telling me that the current is equal to the new. Is this
possible? Any idea to avoid this problem?
Thanks for any help.
Andre
--
Andre Matos
[EMAIL PROTECTED]
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php