Results 1 to 6 of 6

Thread: if something equals something or something else do this

  1. #1
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default if something equals something or something else do this

    Hello everyone,

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

    PHP Code:
    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?
    Last edited by keyboard; 08-06-2011 at 10:30 PM.

  2. #2
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Operators don't work if they're written within a string.

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

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


    - Josh

  3. #3
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    What's the [b] for?

  4. #4
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    Code:
    <?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
    To choose the lesser of two evils is still to choose evil. My personal site

  5. The Following User Says Thank You to james438 For This Useful Post:

    keyboard (08-06-2011)

  6. #5
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Thanks everyone!

  7. #6
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    The [b] was BBCode that I left in there by accident.
    - Josh

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •