SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    usa
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can If ( have more than one expression) ?

    Hello all I seem to have a problem with this script i'm making which will read time with a littel if statement

    This is the code:
    <?php
    //Date Configuration
    $date = date("d");
    $day = date("D");
    $hour = date("H");
    $min = date("i");
    $year = date("y");
    //Update Coding
    if ($day == "Sat") {
    print "Today is Sat";
    } else {
    print "Today is not Fri";
    }
    ?>

    Now what I wanted to do was add another expression to that if statement. Is this possible? How?

  2. #2
    :) delemtri's Avatar
    Join Date
    Jun 2001
    Posts
    579
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if ((expr1) && (expr2) && (expr3)) { stuff; } 
    For example,
    PHP Code:
    if (($name=="delemtri") && ($greatness=="inherent") && ($popcorn="tasty")) { stuff; } 

  3. #3
    midnight coder
    Join Date
    Dec 2000
    Location
    The flat edge of the world
    Posts
    838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes it is possible to have multiple expressions in the if statement, you could have something like:

    PHP Code:
    if (($day == "Sat") || ($day == "Fri")) {
    echo 
    "Today is Saturday or Friday";
    } else {
    echo 
    "Today is not Saturday or Friday";

    Not quite usable in this situation, but you could use:

    PHP Code:
    if (($day == "Sat") && ($day == "Fri")) {
    echo 
    "Today is Saturday and Friday";
    } else {
    echo 
    "Today is not Saturday or Friday";

    For info, go to:

    http://php.net/manual/en/language.operators.logical.php

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    usa
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks

    Thank you all that helped me it works like a charm. Make sure you guys watch out for my new program involving this.
    My site address is http://www.7thsignproductions.cjb.net
    thanks again


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
  •