我試圖重現以下內容作爲一行代碼。PHP:每次增加一個數字5
if($l < 10) $next = 5; return;
if($l < 20) $next = 10; return;
if($l < 30) $next = 15; return;
if($l < 40) $next = 20; return;
if($l < 50) $next = 25; return;
if($l < 60) $next = 30; return;
if($l < 70) $next = 35; return;
if($l < 80) $next = 40; return;
if($l < 90) $next = 45; return;
if($l < 100) $next = 50; return;
(語法上不正確的,但你的想法)
因此,如果數小於10,$其次是5,如果數量少於20那麼它的10
$next = ((round($l, -1)-5));
是接近我可以得到它,但是,讓
5
15
25
35
45
55
65
75
85
沒有預期的5,10,15,20 ..等
寫這個的正確方法是什麼?
其中一個括號沒有正確關閉 – penu 2012-01-28 08:47:00
抱歉(固定它)...但我的回答比您選擇的答案「更加嚴格」,因爲如果您沒有確定結果得到一個不是四捨五入的數字,在我的例子中你會得到5.7 * 5 = 28.5。 – 2012-01-28 08:59:51
好的,謝謝:) .. – penu 2012-01-28 09:03:18