如何从date_sun_info
函数中提取日落、日出?
如何为单个行提取值。
<?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/>";
}
?>
'date_sun_info'返回数组,这意味着您可以通过[]操作符访问其值
<?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");
}
函数值和文档的完整列表如下:https://www.php.net/manual/en/function.date-sun-info.php