Example #1
0
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title>Hour Of Day</title>
    </head>
    <body>
        <?php 
print DisplayGreeting(3);
function DisplayGreeting($hourOfDay)
{
    $time = "";
    $hourOfDay = (int) $hourOfDay;
    print "<p>Hour: " . $hourOfDay . "</p>";
    if ($hourOfDay < 6) {
        $time = "Good Night!";
    } else {
        if ($hourOfDay < 12) {
            $time = "Good Morning!";
        } else {
            if ($hourOfDay < 18) {
                $time = "Good Afternoon!";
            } else {
                if ($hourOfDay < 22) {
                    $time = "Good Evening!";
                } else {
Example #2
0
<?php

function DisplayGreeting($hourOfDay)
{
    $hourOfDay = (int) $hourOfDay;
    $greeting;
    if ($hourOfDay >= 0 && $hourOfDay <= 10) {
        $greeting = "Good Morning";
    } elseif ($hourOfDay > 10 && $hourOfDay <= 16) {
        $greeting = "Good Afternoon";
    } elseif ($hourOfDay > 16 && $hourOfDay <= 24) {
        $greeting = "Good Night";
    } else {
        $greeting = "Error";
    }
    return $greeting;
}
print "<p>" . DisplayGreeting(5) . "</p>";
print "<p>" . DisplayGreeting(16) . "</p>";
Example #3
0
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title>Hour Of Day</title>
    </head>
    <body>
        <?php 
$hourOfDay = 3;
print "<p>Hour: " . $hourOfDay . "</p>";
print "<p>" . DisplayGreeting($hourOfDay) . "</p>";
function DisplayGreeting($hourOfDay)
{
    $time = "";
    if ($hourOfDay < 6) {
        $time = "Good Night!";
    } else {
        if ($hourOfDay < 12) {
            $time = "Good Morning!";
        } else {
            if ($hourOfDay < 18) {
                $time = "Good Afternoon!";
            } else {
                if ($hourOfDay < 22) {
                    $time = "Good Evening!";
                } else {