SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: && versus "and"

  1. #1
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    && versus "and"

    Quick question: is there any real difference betweeing using things like "&&" and "||", or can I simply use "and" and "or" -- is there/will there be some compatibility issue at some point? I prefer the english-substitutes in a simple matter of taste.

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I read the manual correctly, && takes precedence ove AND, but I could be wrong. The link above gives the whole deal for you.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Freddy. If it's just a precendence issue, I don't think I'll have much problem with one or the other. I appreciate it.

  4. #4
    SitePoint Evangelist ucahg's Avatar
    Join Date
    Apr 2001
    Location
    Sarnia, Ontario, Canada
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think you can use the symbols with die. For example:
    [php]// this would work:
    mysql_connect('localhost','username','password')
    or die "Could not connect to database";

    // this would not work:
    PHP Code:
    mysql_connect('localhost','username','password')
      || die 
    "Could not connect to database"
    I could be mistaken, however.
    Love it? Hate it? Helpful? Useless?
    Use the rate button to let me know what you think of my post!

  5. #5
    SitePoint Zealot New Oddity's Avatar
    Join Date
    Jun 2001
    Location
    Georgia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, when running a large amount of code, and you are trying to optomize the speed of it... It takes less time for the computer to parse && then and. So if that nanosecond matters, or it's in a loop and adds up to minutes, you should go with &&...
    --Odd
    "We all live in a yellow subroutine."
    "Some call it insanity; I call it inspiration!"

  6. #6
    ********* Addict
    Join Date
    Apr 2000
    Location
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tend to use && and || because it looks clearer to me - don't know why. I don't worry much about one having a higher priority than the other - I normally use the parenthesis anyway.

  7. #7
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That operator table lists the tilde ~ as an operator. What does it do?

  8. #8
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ~ $a
    Name: Not
    Result: Bits that are set in $a are not set, and vice versa.

    ...from http://www.php.net/manual/en/languag...rs.bitwise.php

  9. #9
    SitePoint Zealot New Oddity's Avatar
    Join Date
    Jun 2001
    Location
    Georgia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ~ is the bitwise not operator. In relation to || or 'not' being the logical operator. Logical operators are used in conditionals and bitwise operators are used in arithmatic functions...
    --Odd
    "We all live in a yellow subroutine."
    "Some call it insanity; I call it inspiration!"

  10. #10
    SitePoint Member
    Join Date
    Aug 2000
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've always prefered && || ect.
    Makes for much easier reading due to the fact that your eyes tend to over look works such as "and" and "or". when quickly glancing.
    I remember falling...
    i remember marching..
    like a one man army..



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
  •