Testing the "while" Statement

The code sets $currentDate to the value of the current time and uses the variable to test for the day of the week ("while NOT friday"). As long as time value is not equal to Friday, loop prints out current day, adds 24 hours to variable value, retests and then re-executes until $currentTime is equal to "Friday". Thr result is an ordered list of the days remaining till Friday. TGIF!!

BEGIN PHP output

Days left before Friday:

  1. Wednesday
  2. Thursday


END PHP output

<?

/*
/** Get current date in number of seconds
*/

$currentDate = time();

/*
/** print some text explaining the output
*/

print("Days left before Friday:\n");
print("<ol>\n");

while(date("l", $currentDate) != "Friday")
{

    /*
    ** Print day name
    */

    print("<li>" . date("l", $currentDate) . "\n");
    
    /*
    ** add 24 hours to currentDate
    */
    $currentDate += (60 * 60 * 24);
}
print("</ol>\n");

// if Friday, run the if loop
if(date("l", $currentDate) == "Friday") {
   print "Today IS ";
   print (date("l", $currentDate));
   }

Back to Bill's PHP