所以我有四个条件需要通过,我认为最好在
PHP中使用switch语句.但是,我需要检查一个整数是否小于或等于或大于等于.
switch ($count) { case 20: $priority = 'low'; break; case 40: $priority = 'medium'; break; case 60: $priority = 'high'; break; case 80: $priority = 'severe'; break; }
使用if()语句,它将如下所示:
if ($count <= 20) { $priority = 'low'; } if ($count <= 40) { $priority = 'medium'; }
在switch-case中是否可能?
解决这个问题的一般情况是:
switch (true) { case $count <= 20: $priority = 'low'; break; case $count <= 40: $priority = 'medium'; break; case $count <= 60: $priority = 'high'; break; default: $priority = 'severe'; break; }