By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,610 Members | 2,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,610 IT Pros & Developers. It's quick & easy.

Why strange IF...ELSE behavior

P: n/a
J-P
Hi all,

I'm getting a strange result with the following IF statement:

$bar = ($foo == 'last') ? true : false;

In my script $foo normaly has a integer value greater than 0, but can have
last as value. But whatever value of $foo $bar always becomes true.
When I use the regular if {....}else{....} I get the same result, always
$bar becomes true.
I've played around with a couple things, like turning the statement around
($foo != 'last') but nothing seems to give the desired result.
Can anyone tell me what I'm doing wrong or how to fix this.

Thanx,
J-P
Jul 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
J-P écrivit:
Hi all,

I'm getting a strange result with the following IF statement:

$bar = ($foo == 'last') ? true : false;

In my script $foo normaly has a integer value greater than 0, but can
have last as value. But whatever value of $foo $bar always becomes
true.


It's due to the silent type casting of php
you should use === instead of ==
--
P'tit Marcel
Jul 16 '05 #2

P: n/a
J-P

It's due to the silent type casting of php
you should use === instead of ==


Thanx that did it, never to late to learn something.
Jul 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.