我有一個奇怪的案例問題,在我的PHP代碼;PHP案件不能與整數
$sm_hours = (int)$sm_hours; // Make it an integer
echo $sm_hours; // is 206
switch ($sm_hours) {
case ($sm_hours = 0 && $sm_hours <= 120):
echo "One";
break;
case ($sm_hours >= 121 && $sm_hours <= 240):
echo "Two";
break;
case ($sm_hours >= 241):
echo "Three";
break;
}
$ sm_hours是206,但我得到的回聲是One not Two。我錯過了什麼?
感謝
嘗試使用intva($ sm_hours);而不是cast(int) – Cr1xus
試試$ sm_hours> = 0 && $ sm_hours <= 120 –
「=」是一個賦值運算符而不是比較運算符。 – Jinandra