I'm a newbie to PHP, but this seems weird. I have in one file: <?php $longhaul = "no"; ?> Code (markup): Then in another file I have this: <?php if ($longhaul = "yes") { print "[COLOR="Red"]The answer is yes[/COLOR]"; } ?> Code (markup): The problem is that, although the if statement is false, it prints "The answer is yes" anyway. Other than this, the files are working ok. It's only this if that isn't working. I checked the variable with a simple print without the if; it is indeed "no". Can anyone help??? This is so simple and I have tried all I know to try but can't get rid of "The answer is yes". Thanks!
$longhaul = "yes" always equal `true` as a result of '=' operation. So you must use $longhaul == "yes"
Thanks guys, it works of course! I knew the answer would be something super-simple. In my defense however, I'd looked at 3 or 4 online tutorials and none of them had a double == mark. Huh. Oh well, thanks for the replies and links. I really try to figure these out before posting
If none of the tutorials you're looking at had double equals for comparisons, I would suggest finding new tutorials!
Exactly what I was thinking! I even looked on php.net, but their example used a different sort of structure, so there were only single ='s. Not their fault, just my scanning too quickly, looking at the wrong elements.
I often use = in if() conditions to cache an expression evaluation, or function call, and use the value later.