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";
}
}
}