Kaylyn's Code for Greetingsif / elseif/ switch and ternary Examples
Hour is: 2
Hour is: 2
<?php
include('includes/header.php');
error_reporting(E_ALL);
date_default_timezone_set('America/Detroit');
echo("<h1>Kaylyn's Code for Greetings</h2>");
echo('<h2>if / elseif/ switch and ternary Examples</h2>');
$hour = date('G');
echo("<p>Hour is: $hour</p>");
if ($hour >= 0 && $hour < 6)
{
echo('<H3>You should be sleeping!</h3>');
}
if ($hour >= 6 && $hour < 9)
{
echo('<H3>Get ready for work!</h3>');
}
if ($hour >= 9 && $hour < 17)
{
echo('<H3>You should be at work!</h3>');
}
if ($hour >= 17 && $hour <= 24)
{
echo('<H3>Time to rest and get ready for tomorrow!</h3>');
}
if ($hour >= 0 && $hour < 6)
{
echo('<H3>You should be sleeping!</h3>');
}
elseif ($hour >= 6 && $hour < 20)
{
echo('<H3>You should be awake!</h3>');
}
elseif ($hour >= 20 && $hour < 23)
{
echo('<H3>Time to get ready to end the day!</h3>');
}
else
{
echo('<H3>Good Night</h3>');
}
switch ($hour)
{
case ($hour >= 0 && $hour < 7):
echo('<H3>Not Answering Phone Calls!</h3>');
break;
case ($hour >= 7 && $hour < 15):
echo('<H3>Answering and Making Phone Calls</h3>');
break;
case ($hour >= 15 && $hour < 20):
echo('<H3>Answering Phone Calls but Not Making Them</h3>');
break;
case ($hour >= 20 && $hour <= 24):
echo('<H3>Only Answering Emergency Calls!</h3>');
break;
}
echo('<br><br>');
echo('<h3>Simple IF/ELSE</h3>');
if ($hour < 9)
{
$amPM = "Time to Wake Up!";
}
else
{
$amPM = "You should already be awake and doing stuff!";
}
echo($amPM);
echo('<h3>Ternary Example</h3>');
$amPM = ($hour < 7) ? "Still Asleep" : "Awake for the day";
echo($amPM);
include('includes/footer.php');
?>