Using comparison operators in a PHP 'switch' statement

前端 未结 6 2067
予麋鹿
予麋鹿 2020-12-13 17:41

I have four conditions that I need to go through and I thought it would be best to use the switch statement in PHP. However, I need to check whether an integer

6条回答
  •  天命终不由人
    2020-12-13 17:54

    A more general case for solving this problem is:

    switch (true) {
        case $count <= 20:
            $priority = 'low';
            break;
    
        case $count <= 40:
            $priority = 'medium';
            break;
    
        case $count <= 60:
            $priority = 'high';
            break;
    
        default:
            $priority = 'severe';
            break;
    }
    

提交回复
热议问题