什麼將通過此語句?通過PHP表達式將值傳遞給浮點數
$a=($_POST['a']*1337)+1.7;
$a=!preg_match('/[^0-9]/',''.$a)?(int)round($a)-33:1337;
我的目標是讓$ a =='float';
什麼將通過此語句?通過PHP表達式將值傳遞給浮點數
$a=($_POST['a']*1337)+1.7;
$a=!preg_match('/[^0-9]/',''.$a)?(int)round($a)-33:1337;
我的目標是讓$ a =='float';
$a=!preg_match('/[^0-9]/',''.$a)?(int)round($a)-33:1337;
$a
設置爲preg_match()
返回的否定,測試正則表達式[^0-9]
上的三級結果$a
與空字符串連接。答案是round()
ed並鑄造爲整數$a
-33
或1337
。
我說這段代碼可以寫成更漂亮......
$a = preg_match('/\D/', (string) $a) ? 1337 : (int) round($a) - 33;
現在,對不起:P – zarcel 2011-03-22 06:41:55
更好的方式(KISS理論)注
$a=$_POST['a']*1337+1.7;
if(preg_match('/\D/', (string) $a))
$a = 1337
else
$a = (int) round($a) - 33;
:中(int) round($a)
相反,你應該使用floor
或ceil
@alex感謝您的想法... – diEcho 2011-03-22 06:52:32
第一行評估分配給無處。整個問題都很模糊。 – zerkms 2011-03-22 06:37:01
我的壞,對不起,現在修復 – zarcel 2011-03-22 06:41:09