On Thu, 25 Oct 2001 02:04:14 -0700 (PDT) impersonator of [EMAIL PROTECTED]
(Rasmus Lerdorf) planted I saw in php.general:
if(strpos(abcdef,abc)) { ... }
and then be confused that the condition appeared not to be met. What they
actually should have done was:
if(strpos(abcdef,abc)!==false)
why does
? $qty = 0 ; if ($qty != test) print qty is not test; ?
work properly but not the following
? $qty = 0 ; if ($qty != test) print qty is not test; ?
Thanks,
Robin
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands,
Hello Robin,
Very simple. :)
RC ? $qty = 0 ; if ($qty != test) print qty is not test; ?
$qty is string, so PHP compares 0 with test char by char. chr(0)
isn't equal t.
RC ? $qty = 0 ; if ($qty != test) print qty is not test; ?
In this case $qty is integer value, so PHP tries to convert test
in the 2nd example, the string is
casted to int, and the int cast of test is 0.
-Original Message-
From: Robin Chen [mailto:[EMAIL PROTECTED]]
Sent: Thursday, October 25, 2001 4:06 AM
To: [EMAIL PROTECTED]
Subject: [PHP] = 0 and = 0
why does
? $qty = 0 ; if ($qty != test) print qty
? $qty = 0 ; if ($qty != test) print (qty is not test); ?
? $qty = 0 ; if ($qty != test) printf(qty is not test); ?
I just tested those two lines with php 4.0.6 and they both work.
There is a difference though.
If you set $qty=0; then $qty has no value.
But if you set $qty=0, it has a value.
If you set $qty=0; then $qty has no value.
Of course it has a value. The value is 0.
Quite distinct from not having a value, or in proper terms, not being set.
Try this:
var_dump($qty);
$qty = 0;
var_dump($qty);
Well, I will save you the trouble, it outputs:
NULL
int(0)
Type
If you set $qty=0; then $qty has no value.
Of course it has a value.
No it doesn't have a value.
PHP interprets 0 as null.
A very easy way for you to check:
$value=0;
if(!$value) printf($value doesn't have a value (it didn't even print
0)br\n);
$value=0
if($value) printf($value does
Thank you, that was it. I needed to test the variable against both an
integer and a string, so I ended up using (string) when I need to
compare a string. Rest of the time, it's an integer.
Robin
Rasmus Lerdorf wrote:
If you set $qty=0; then $qty has no value.
Of course it has a value.
The integer 0 is equal to False, but not Null.
Robin
Kodrik wrote:
If you set $qty=0; then $qty has no value.
Of course it has a value.
No it doesn't have a value.
PHP interprets 0 as null.
A very easy way for you to check:
$value=0;
if(!$value) printf($value doesn't have
Kodrik, you are picking the wrong person to argue with. ;)
If you set $qty=0; then $qty has no value.
Of course it has a value.
No it doesn't have a value.
PHP interprets 0 as null.
Completely incorrect.
A very easy way for you to check:
$value=0;
if(!$value) printf($value
You are right, 0 didn't show as a value.
But his two lines still don't need typecasting, they both work:
http://24.234.52.166
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list
$qty=0; then $qty has no value.
Of course it has a value.
No it doesn't have a value.
PHP interprets 0 as null.
A very easy way for you to check:
$value=0;
if(!$value) printf($value doesn't have a value (it didn't even print
0)br\n);
$value=0
if($value) printf
You are right, 0 didn't show as a value.
But his two lines still don't need typecasting, they both work:
http://24.234.52.166
I don't mean to pick on you, but no, you are wrong. And I am only doing
this because so many people get confused on this point and I always see
questions related
Check the link I posted.
http://24.234.52.166
There is the code I wrote and it's output.
The two lines print.
You can explain me why tomorrow they print on my server and not yours.
Good night
But his two lines still don't need typecasting, they both work:
http://24.234.52.166
I don't mean
Rasmus Lerdorf [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
The integer 0 is equal to False, but not Null.
Not quite true. 0 evaluates to false. They are not equal. Try this:
[...]
So be careful and try to think of 0 and false as distinct and
Hi John!
The integer 0 is equal to False, but not Null.
Not quite true. 0 evaluates to false. They are not equal.
Try this:
[...]
So be careful and try to think of 0 and false as distinct
and separate
entities and you will avoid coding mistakes like this.
Is this
16 matches
Mail list logo