How to extract sunset, sunrise from date_sun_info
function?
How to extract values for individual rows.
<?php
$l = date('Y-m-d');
$sun_info = date_sun_info(strtotime($l), $lat, $lon);
foreach ($sun_info as $key => $val) {
echo "$key: " . date("H:i:s", $val) . "\n<br/>";
}
?>
CodePudding user response:
'date_sun_info' returns array, which means you can access its values by [] operator
<?php
$l = date('Y-m-d');
$sun_info = date_sun_info(strtotime($l), $lat, $lon);
if($sun_info !== false) {
$sunrise = $sun_info['sunrise']; //this is what you want
} else {
die("'date_sun_info' failed");
}
complete list of values and doc for the function is here: https://www.php.net/manual/en/function.date-sun-info.php
CodePudding user response:
How to change Unix time to h-i-s. I try, but it doesn't work.
$l = date('h-i-s');
$sun_info = date_sun_info(strtotime($l), $lat, $lon);
echo $sunrise = $sun_info['nautical_twilight_end'];