我想定義一組7天工作周的開放時間。當訪問者訪問網頁時,我想在特定國家(加勒比海尼維斯)顯示當前時間和日期,然後將其與一組定義的開放時間進行比較,以顯示兩個字幕中的一個1)打開2)關閉。具體來說,這是我想生產什麼:將當前時間與數組中的值進行比較true/false
我使用這個迄今爲止獲得當前的時間和設置的陣列,但我怎麼比較這兩個?
<?php
function get_timee($country,$city) {
$country = str_replace(' ', '', $country);
$city = str_replace(' ', '', $city);
$geocode_stats = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address=$city+$country,&sensor=false");
$output_deals = json_decode($geocode_stats);
$latLng = $output_deals->results[0]->geometry->location;
$lat = $latLng->lat;
$lng = $latLng->lng;
$google_time = file_get_contents("https://maps.googleapis.com/maps/api/timezone/json?location=$lat,$lng×tamp=1331161200&key=xxx");
$timez = json_decode($google_time);
$d = new DateTime("now", new DateTimeZone($timez->timeZoneId));
return $d->format('H:i');
}
$array = array(
"Monday" => "10:00 - 18:00",
"Tuesday" => "10:00 - 18:00",
"Wednesday" => "10:00 - 18:00",
"Thursday" => "10:00 - 18:00",
"Friday" => "18:00 - 23:00",
"Saturday" => "18:00 - 23:00",
"Sunday" => "Closed"
);
?>
其<?php echo get_timee("Federation of Saint Kitts and Nevis","Nevis"); ?>
。我們目前...
你不應該公開分享您的API密鑰。 – treegarden
我把它刪除了,比尼維斯晚得多..我的意思是永遠不會。 – RiggsFolly