Hi,
I'm just getting started with php and wrote a simple function that uses timestamps to find the angle formed by the hour, minute and second hands on a traditional clock. I was hoping someone could look it over and see if i'm writing it corrently. The function works as expected, I just wanted to see if there was a better or more efficient way of writing it. Also, is it possible to use a function (ie: time()) as the default value of a function parameter, I tried but couldn't get it to work.
Thanks!
// Function timeangle
// This function takes a UNIX timestamp and finds the angle
// of the hour, minute and second hands on a clock.
//
// Returns an associative array with h, m, s pointing to each of the found angles
function timeangle($time)
{
// if time is left empty use current time
$time = (!$time) ? time() : $time;
// create an array with values for hour, minutes and seconds and convert
// each to seconds
$time = array("h" => ((date("g", $time)) * 60 * 60),
"m" => ((date("i", $time)) * 60) ,
"s" => date("s", $time));
// convert each value to an angle
$time["h"] = (($time['h'] + $time['m'] + $time['s']) * 360) / 43200;
$time["m"] = (($time['m'] + $time['s']) * 360) / 3600;
$time["s"] = ($time['s'] * 360) / 60;
// Return array
return $time;
}