Like what
$order['status'] == 9 || $order['status'] == 10 || $order['status'] == 11
Similar to this, if two or three is still acceptable, but if there are more than 3 conditions I can not accept the wording.
Later, the method of using In_array () was relatively brief.
Would like to ask the next PHP there is no better than In_array () the wording of a better point. Thank you
Reply content:
Like what
$order['status'] == 9 || $order['status'] == 10 || $order['status'] == 11
Similar to this, if two or three is still acceptable, but if there are more than 3 conditions I can not accept the wording.
Later, the method of using In_array () was relatively brief.
Would like to ask the next PHP there is no better than In_array () the wording of a better point. Thank you
Sauce?
php
switch($order['status']){ case FINISHED: case PENDING: case PROCESSING: //logic break; default: break;}
Isn't itin_array($order['status'], [9, 10, 11])
Like your example, change to switch on the line, simple and intuitive also reasonable;
If there are too many conditions to avoid, that is, if you can only use if you feel uncomfortable with something else, it is advisable to change the wording:
if ($order['status'] == 9 || $order['status'] == 10 || $order['status'] == 11) {}
I am a party of curly braces on another line, but in this case, you can also
if ($order['status'] == 9 || $order['status'] == 10 || $order['status'] == 11) {}
It is also advisable to put literal constants on the left.
If the judgment conditions in the If are particularly long (I've seen some branches that need to judge three or four variables, | | And && seven or eight), it is recommended to write the judging condition as a separate function