我在玩PHP,目前我正在使用case switch
函數。我想創建最多100個隨機數,並根據隨機數輸出回顯消息。PHP案例切換打印消息
我的PHP代碼:
$number = rand(1, $limit);
switch($number){
case "range1":
if($number >=1 || $number <=25){
print 'You win nothihg';
}else{
print 'Your Score is: '.$number;
}
break;
case "range2":
if($number >25 || $number <=50){
print 'You win Small Prize';
}else{
print 'Your Score is: '.$number;
}
break;
case "range3":
if($number >50 || $number <=75){
print 'You win Medium Prize';
}else{
print 'Your Score is: '.$number;
}
break;
case "range4":
if($number >75 || $number <=100){
print 'You win Large Prize';
}else{
print 'Your Score is: '.$number;
}
break;
default:
if($number <=75) {
print 'Keep tryintg untill you win Large';
}
}
我有這些消息沒有得到顯示問題.....我不知道在哪裏,我在這裏走錯了..?
你爲什麼要將一個隨機數與字符串「range1」進行比較? – slugonamission 2014-10-02 09:15:11