Log in

View Full Version : Resolved if something equals something or something else do this



keyboard
08-05-2011, 10:17 PM
Hello everyone,

I have a section of code which looks something like this,


if ("$usercheck == george")
{
echo 'Hello';

}


I would like to change it so that if $usercheck == george or fred or bob

than it would say hi.
So they could be george and it would say hi or they could be fred and it would say hi or they could be bob and it would say hi.
Any help?

JShor
08-06-2011, 03:01 AM
Operators don't work if they're written within a string.

So $usercheck == "george" would work, but "$usercheck == george" will not.



[B]if ($usercheck == "george")
{
echo 'Hello';

}

keyboard
08-06-2011, 05:21 AM
What's the [b] for?

james438
08-06-2011, 05:34 AM
<?php
$t='fred';
if ($t=='fred'||$t =='george')echo"hi<br>";
$t="george";
if ($t=='fred'||$t =='george')echo"hi<br>";
$t="bob";
if ($t=='fred'||$t =='george')echo"hi<br>";
if ($t=='fred' or $t =='george' or $t=='bob')echo"hi<br>";
?>

read more here: http://www.php.net/manual/en/language.operators.logical.php

keyboard
08-06-2011, 05:52 AM
Thanks everyone!

JShor
08-06-2011, 03:48 PM
The [b] was BBCode that I left in there by accident.