english

learn php

learn css

learn html

learn javascript

learn php

7. functions

solution 7.1
1 minute / 126 words

seven / solution 7.1

<?php

function getAngle(float $part, int $whole)
{
    return round((360 * $part) / $whole, 1);
}

function showClockAngles($time)
{
    //save starting time
    $startTime = $time;

    // ensure useful hours
    $time["hour"] >= 12 && ($time["hour"] -= 12);

    // get fractional hours and minutes
    $time["minute"] += $time["second"] / 60;
    $time["hour"] += $time["minute"] / 60;

    // write time and hand angles
    print_r("it is currently " . $startTime["hour"] . "." . $startTime["minute"] . "." . $startTime["second"] . ".\n\n");
    print_r("hour hand at " . getAngle($time["hour"], 12) . "°\n");
    print_r("minute hand at " . getAngle($time["minute"], 60) . "°\n");
    print_r("second hand at " . getAngle($time["second"], 60) . "°\n");
}

function getTime($tz)
{
    // create array of current time in selected time zone
    date_default_timezone_set($tz);
    return ["hour" => date("H") + 0, "minute" => date("i") + 0, "second" => date("s") + 0];
}

showClockAngles(getTime("America/St_Johns"));

learn php

learn css

learn html

learn javascript

powered by akelei. an avi sato project.