Page 1 of 1
This may be interesting to you
Posted: Mon Jul 20, 2009 3:42 am
by prathyush
Why does the second return success do you think?
Code: Select all
$txnResponseCode = "E";
if ($txnResponseCode != "0") {
echo 'fail<br>';
} else {
echo 'success<br>';
}
if ($txnResponseCode != 0) {
echo 'fail<br>';
} else {
echo 'success<br>';
}
Re: This may be interesting to you
Posted: Mon Jul 20, 2009 3:44 am
by Benjamin
Because the value of $txnResponseCode is true when compared to a boolean value of false.
You can cast the data types.
Code: Select all
if ((string) $txnResponseCode !== (string) 0) {
} else {
}
Re: This may also be interesting to you
Posted: Mon Jul 20, 2009 3:53 am
by jackpf
I had problems with this, when comparing a variable's value to 0 with in_array().
No matter what the value was, it would always return true when comparing to 0.
After reading the manual, it turns out that in_array() has a third parameter [, bool $strict], which, when set to true, also checks datatypes.
Re: This may also be interesting to you
Posted: Mon Jul 20, 2009 2:36 pm
by califdon
jackpf wrote:I had problems with this, when comparing a variable's value to 0 with in_array().
No matter what the value was, it would always return true when comparing to 0.
After reading the manual, it turns out that in_array() has a third parameter [, bool $strict], which, when set to true, also checks datatypes.
WHAT?!! You READ THE MANUAL?!! That's heresy!
To: prathyush
Please use meaningful Subject lines for posting in this forum. The Subject line should indicate what the post is about, not a general comment, like "This may be interesting to you" or "Please help me!"
Re: This may also be interesting to you
Posted: Mon Jul 20, 2009 2:56 pm
by jackpf
califdon wrote:jackpf wrote:I had problems with this, when comparing a variable's value to 0 with in_array().
No matter what the value was, it would always return true when comparing to 0.
After reading the manual, it turns out that in_array() has a third parameter [, bool $strict], which, when set to true, also checks datatypes.
WHAT?!! You READ THE MANUAL?!! That's heresy!
I know...it's hard to believe that some people actually read the manual before asking for help
