Results 1 to 4 of 4

Thread: Php if a AND b

  1. #1
    Join Date
    Nov 2006
    Location
    Liverpool/Manchester
    Posts
    2,457
    Tokens
    0

    Latest Awards:

    Default Php if a AND b

    Hey,

    This has been annoying me for a bit now, I've tried googling, just isn't happening for me lol

    I want to do something like this

    if A and B are true

    do this

    else

    do this

    +rep to any help
    Joe


  2. #2
    Join Date
    Dec 2006
    Location
    UK
    Posts
    6,444
    Tokens
    6,671

    Latest Awards:

    Default

    if (a && b) {
    do this
    } else {
    do this
    }

    you mean that? orrrr

  3. #3
    Join Date
    Jun 2005
    Location
    /dev/null
    Posts
    4,918
    Tokens
    126

    Latest Awards:

    Default

    Yeah, join the statements with && (logical AND) if you want both conditions satiisfied or || for either to be satisfied (logical OR).

    PHP Code:
    $a true;
    $b false;

    if (
    $a && $b) {
        echo 
    "Both are true!";
    } else {
        echo 
    "One of them or both are not true."// This will be the result.
    }

    if (
    $a || $b) {
        echo 
    "At lease one is true"// This will be the result.
    } else {
        echo 
    "Neither is true.";

    Last edited by N!ck; 14-04-2011 at 12:03 AM.

  4. #4
    Join Date
    Nov 2006
    Location
    Liverpool/Manchester
    Posts
    2,457
    Tokens
    0

    Latest Awards:

    Default

    Thanks a lot, works
    Joe


Posting Permissions

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