SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Basic IF Question

    Hi all,
    Just wondering what these snippets actually mean, am I right in saying:

    PHP Code:
    <?php if ($smart): ?>
    <p>If $smart has a value, show this paragraph else don't show anything</p>
    <?php endif; ?>
    PHP Code:
    <?php if ($smart || $desktop): ?>
    <p>If $smart and $desktop both have values, show this paragraph else don't show anything</p>
    <?php endif; ?>
    Are these simply shorthand if statements?
    And what does || mean?


    Thanks
    Barry
    The more you learn.... the more you learn there is more to learn.

  2. #2

  3. #3
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


    Just what I thought, just tried this locally, works great, thanks for the links.
    The more you learn.... the more you learn there is more to learn.

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,891
    Mentioned
    138 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by computerbarry View Post
    PHP Code:
    <?php if ($smart): ?>
    <p>If $smart has a value, show this paragraph else don't show anything</p>
    <?php endif; ?>
    Not completely. It will show the text if $smart is set and has a "positive value". For example, if $smart is set to false the text won't show.
    Please be aware that doing it this way can cause an E_NOTICE warning if $smart isn't set at all. Better would be to check for isset($smart) to check if it has any value, or !empty($smart) to check check if it has any value and that value is not negative.

    You may want to look those up in da manual: isset, empty
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  5. #5
    SitePoint Member
    Join Date
    Oct 2012
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    || means OR,
    && means AND


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
  •