![]() |
php 在使用if判断的时候 如果是多个逻辑或(||)条件 有没有简写的方法
如果条件太多无可避免的情况,即只能用if,就算用别的也感觉别扭不对劲的时候, 建议换一种写法:
if ($order['status'] == 9 || $order['status'] == 10 || $order['status'] == 11) { } 我是花括号部另起一行党, 但在这种情况下,也可以 if ($order['status'] == 9 || $order['status'] == 10 || $order['status'] == 11) { } 另外建议把字面量常量放在左边。 |
如果if里的判断条件特别特别长(我见过有些分支需要判断三四个变量,||和&&用了七八个),建议把判断条件写成单独的函数
|
| All times are GMT +8. The time now is 06:06 AM. |
Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.