php - 交换机总是比很多其他的更好吗?

I am not so familiar with switch in php, but I heard if your code has a lot of elseif, it's better to use switch instead. I tried to change the code below into switch, but since I am checking two or three values at each elseif, it seems using elseif instead of switch is more logical to me (maybe I'm wrong).

So my question is, what do you suggest for the code below? Elseif or switch?

And if I want to change the code into switch, could you give me some hint?

Thank you so much in advance!

(By the way, block_check and report_check are checkboxes, and reported_msg is text)

public function block_user(){
    if(isset($_POST['submitted'])){

        $block_check = $_POST['block_check'];
        $report_check = $_POST['report_check'];     
        $reported_msg = $_POST['reported_msg']);

        if((!($block_check)) && (!($report_check))){
            echo "dont send, both not checked";

        }elseif(($report_check) && ($reported_msg == '')){
            echo "dont send, msg box is empty";

        }elseif((!($report_check)) && ($reported_msg != '')){
            echo "dont send, report_check is not checked";

        }elseif(($block_check) && (!($report_check)) && ($reported_msg == '')){
            echo "just process block";

        }elseif((!($block_check)) && ($report_check) && ($reported_msg != '')){
            echo "just process report";

        }elseif(($block_check) && ($report_check) && ($reported_msg != '')){
            echo "process both block and report";
        }
    }
}

Switch is really good in some situations but really bad for others. In your specific situation I would use if/elseif conditions.

I use switch when the condition is simple and the expression is simple. If the condition has more than one variable and the expression is longer than about three lines I wouldn't use a switch.

Here's a good example of a good switch:

switch ( $type ) {
    case 'banana': 
        $valid = true;
        $price = 1;
        break;
     case 'apple': 
        $valid = false;
        $price = 2.52;
        break;
}

To optimize your code, you want to put the most frequently used if statements at the top of the block of elseif statements. Otherwise, the only difference is in readability of your code, which is actually a great reason to use switch statments.

It's about readability and taste for the most part, quite honestly. I prefer elseif statements because it allows for more flexibility if conditions become more complex.