請問下在接口里做個時間判斷具體應該怎么寫,如果現(xiàn)在是上午就輸出上午的圖片,如果是中午就輸出中午的圖片,如果是下午就輸出下午的,如果是晚上就輸出晚上的
// 判斷當前時間段
if (hours >= 0 && hours <= 10) {
state = `../../static/img/zaoshang.gif`;
} else if (hours > 10 && hours <= 14) {
state= `../../static/img/zhongwu.gif`;
} else if (hours > 14 && hours <= 18) {
state= `../../static/img/xiawu.gif`;
} else if (hours > 18 && hours <= 24) {
state= `../../static/img/wanshang.gif`;
}
return state;
頂部寫一個
---
$houer = date("G");
---
houer改成$houer
---if語句寫的這么好,居然把php變量沒寫對
開源是一種精神,但不是義務,幫忙是情分,不幫也不要抱怨,建議大家多研究代碼、多閱讀代碼、多翻閱社區(qū)歷史問題!
為什么返回的不是圖片呀
php實在不怎么會忘指教
<?php $houer = date("G"); $return =[]; $data = // 判斷當前時間段 if ($hours >= 0 && $hours <= 10) { state = `../../static/img/zaoshang.gif`; } else if ($hours > 10 && $hours <= 14) { state= `../../static/img/zhongwu.gif`; } else if ($hours > 14 && $hours <= 18) { state= `../../static/img/xiawu.gif`; } else if ($hours > 18 && $hours <= 24) { state= `../../static/img/wanshang.gif`; }回復@官方插件技術(shù)-周若塵
php語法都寫錯了,肯定是錯的
<?php $houer = date("G"); // 判斷當前時間段 if ($hours >= 0 && $hours <= 10) { $return = `../../static/img/zaoshang.gif`; } else if ($hours > 10 && $hours <= 14) { $return= `../../static/img/zhongwu.gif`; } else if ($hours > 14 && $hours <= 18) { $return= `../../static/img/xiawu.gif`; } else if ($hours > 18 && $hours <= 24) { $return= `../../static/img/wanshang.gif`; }回復@易學習 為什么這段代碼沒起效果啦,現(xiàn)在是下午了,但是輸出的還是早上
<?php $houer = date("G"); // 判斷當前時間段 if ($hours >= 0 && $hours <= 10) { $return = "zaoshang"; } else if ($hours > 10 && $hours <= 14) { $return= "zhongwu"; } else if ($hours > 14 && $hours <= 18) { $return= "xiawu"; } else if ($hours > 18 && $hours <= 24) { $return= "wanshang"; }字母都寫錯了,你說你細不細心??
這種判斷在小程序里面都可以用js判斷,白白浪費服務器流量和速度
回復@易學習 學習了,謝謝指點
回復@Fake 我就是像弄個動態(tài)的圖片,如果放小程序里判斷就只能寫死了