i ran into this problem and i dont remember how i worked around it.
http://php.net/isset
if($_REQUEST['value'] == 1)
{
// do something
}
else if($_REQUEST['value'] == 0)
{
// do something
}
even if i don't do ?value=0 its always prints something.. i want to make
an
on/off value
Richard Lynch wrote:
i ran into this problem and i dont remember how i worked around it.
http://php.net/isset
I would also use isset. Or you can use the identical (===) comparison
instead of the equivalent (==) comparison to check for 0.
--
Teach a man to fish...
NEW? |
To view the terms under which this email is distributed, please go to
http://disclaimer.leedsmet.ac.uk/email.htm
On 10 January 2005 21:20, Chadwick, Russell wrote:
The function this is from sometimes uses $_POST or $_GET input, so
sometimes its comparing 1337 with '1337' and === would break
[snip]
Could anyone tell me why this code echos?
?php
$value = 0;
$curval = 'A';
if ($value == $curval) {
echo WTH, Overbr;
}
?
[/snip]
Because it has an echo statement in it. And '==' is not '==='
From http://us3.php.net/manual/en/language.operators.comparison.php
If you compare an
Ahh.. the trick question. hah.. Ok, let me see if I remember this (although it
doesn't seem to follow the logic in my head.. I know someone else will explain
it better but let me take a crack at it):
When comparing a two different variable types that PHP thinks it knows how to
compare, it
Chadwick, Russell wrote / napĂsal (a):
Could anyone tell me why this code echos?
?php
$value = 0;
$curval = 'A';
if ($value == $curval) {
echo WTH, Overbr;
}
?
Try ===
If you use ==
$value is compared to $curval
$value is integer so
php converts $curval to integer
so it contains no digtis so
On Mon, 10 Jan 2005 10:26:16 -0800, Chadwick, Russell
[EMAIL PROTECTED] wrote:
Could anyone tell me why this code echos?
?php
$value = 0;
$curval = 'A';
if ($value == $curval) {
echo WTH, Overbr;
}
?
The string is converted to an integer when compared with an integer.
See this
From: Brad Pauly [mailto:[EMAIL PROTECTED]
Sent: Mon 2005-01-10 11:41
To: Chadwick, Russell
Cc: php-general@lists.php.net
Subject: Re: [PHP] Comparison Operator
On Mon, 10 Jan 2005 10:26:16 -0800, Chadwick, Russell
[EMAIL PROTECTED] wrote:
Could anyone tell me why this code echos
Chadwick, Russell wrote:
The function this is from sometimes uses $_POST or $_GET input, so
sometimes its comparing 1337 with '1337' and === would break that.
so I'll have to use something like:
if (($value == $curval) !(is_string ($curval) ($value == 0)))
unless there is a better way
Gabe wrote:
I was looking at the comparison operators page and noticed that these
two operators were listed as PHP4 only. Is that an error, or are
they really not used in PHP5? I don't want to use them if they're
going to break when I upgrade. And if they aren't included, then
does
Michael Sims wrote:
Gabe wrote:
I was looking at the comparison operators page and noticed that these
two operators were listed as PHP4 only. Is that an error, or are
they really not used in PHP5? I don't want to use them if they're
going to break when I upgrade. And if they aren't included,
* Thus wrote Michael Sims:
Gabe wrote:
I was looking at the comparison operators page and noticed that these
two operators were listed as PHP4 only. Is that an error, or are
they really not used in PHP5? I don't want to use them if they're
going to break when I upgrade. And if they
12 matches
Mail list logo