Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: PHP Terms

  1. #1
    Regular Coder UrbanTwitch's Avatar
    Join Date
    Apr 2006
    Posts
    485
    Thanks
    44
    Thanked 1 Time in 1 Post

    PHP Terms

    Hello everyone I would like to know the difference between using && and &

    Also whats the difference between using || or | instead of && or &

    One last thing: difference between == and =

    Thank you for reading!
    Last edited by UrbanTwitch; 08-15-2008 at 06:28 AM.
    Formerly MysticScript

    6+ years club

  • #2
    Regular Coder
    Join Date
    Jul 2008
    Posts
    136
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Well from what I understand for the = sign at least, if you are using an if statement you would want to use ==, it won't work for =. But if you are making a string equal something use the single =.

    PHP Code:
    if ($string ==)
    $string 
    So the way I see it the double is a check to see, while the single makes it equal to.

  • #3
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    See the manual on operators, esp. bitwise vs. logical operators and assignment vs. comparison operators.

    dumpfi
    Last edited by dumpfi; 08-15-2008 at 10:04 AM.
    "Failure is not an option. It comes bundled with the software."
    ....../)/)..(\__/).(\(\................../)_/)......
    .....(-.-).(='.'=).(-.-)................(o.O)...../<)
    ....(.).(.)("}_("}(.)(.)...............(.)_(.))Ż/.
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
    Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

  • #4
    New Coder
    Join Date
    Dec 2007
    Posts
    96
    Thanks
    8
    Thanked 1 Time in 1 Post
    Intresting, I thought the '||' , 'OR' - '&&' , 'AND' operators are the same !! but they dont.

  • #5
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    || means OR. So like fish=water || fish=fins.

    && means AND (ALSO). So say if members id equals 12, && members membership equals active.

    & is just a text character.

    A single equal sign assigns a value =
    Such as $name = "Bob"; now you assigned the variable $name to hold the information Bob.

    A double equal == is to check if something is equal exactly the same.
    If $name == "Bob". If its true it will process.

    Also another one is != that means not equal to.
    So if $name != "Bob" then it will process if the name is not bob.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    & - Bitwise AND
    | - Bitwise OR
    ^ - Bitwise XOR
    ~ - Bitwise NOT
    << - Bitwise LEFT SHIFT
    >> - Bitwise RIGHT SHIFT

    = - Assign Right INTO Left
    == - Comparative operator Left to Right
    === - Comparative operator Left to Right identical

    || - Logical OR
    OR - Logical OR (lower precedence priority)
    && - Logical AND
    AND - Logical AND (lower precedence priority)

    AND is not the same as &&, and OR is not the same as ||. They are close, but its the precedence that changes.
    Usages:
    PHP Code:
    $a 1;
    $b 3;
    echo 
    $a == $b// False
    echo $a == '1'// True
    echo $a === '1'// False
    echo $a $b// Creates 1
    echo $a $b// Creates 3
    echo $a $b// Creates 2
    echo ~$a// Creates... -2 I believe
    echo $a >> 2// Creates 4
    echo $b << 2// Creates 0

    echo $a == AND $b == 3// True
    echo $a == OR $a == && $b == 3// True 
    I didn't test anything, but I think I got the logical ones right. I never use the operator precedence to control the variable orders. I always wrap my control orders with brackets since it more accurately represents what the mathematical function would look like.
    Last edited by Fou-Lu; 08-17-2008 at 01:36 AM.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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