SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Else tag

  1. #1
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Else tag

    Hello,

    In a PHP "if" segment, is the "else" condition required?

    compuwhiz7

  2. #2
    SitePoint Evangelist worksdev's Avatar
    Join Date
    Mar 2002
    Location
    Central, PA - originally from Monterey, CA
    Posts
    497
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by compuwhiz7
    Hello,

    In a PHP "if" segment, is the "else" condition required?

    compuwhiz7
    Hi compuwhiz7

    No it is not. Here are a couple tutorials on control structures in PHP:

    http://hotwired.lycos.com/webmonkey/...tw=programming

    http://www.onlamp.com/pub/a/php/2001...undations.html

    and the manual:

    http://www.php.net/manual/en/control-structures.php

    Best Regards,
    worksdev
    Church Website Design by Enlighten Web Services -
    Web design-hosting-support for Christian ministries
    Friendly Community of Webmasters
    Christian Websites :: Christian Web Design

  3. #3
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi.

    No


    Okay, a bit longer:

    You can use this without problems

    PHP Code:
    $foo 13;
    if (
    $foo == 42) {
       
    // do something
    }

    // no else - proceed with the normal code 
    Inside an if block you cannot use else without another if

    PHP Code:
    if ($foo == 123) {
       else { ... }

    This code does not work.

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, people!


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
  •