当我从6个选择选项中选择一个/两个/三个/四个/五个/六个时,如何减少条件检查次数?

Example: When I have only two select options

input_one = 'one'; 
input_two = 'two';

when I select only input_one

if((isset($_POST['input_one']) && (!isset($_POST['input_two']) {
    //query 
}

When I select only input_two

elseif((!isset($_POST['input_one']) && (isset($_POST['input_two'])) {
    //query 
}

When I don't select any of those

elseif((!isset($_POST['input_one']) && (!isset($_POST['input_two'])) {
    //query 
}

When I select both of them

elsif((isset($_POST['input_one']) && (!isset($_POST['input_two'])) {
    //query 
}

but when I have 6 input options then I need to write a number of conditions. How do I reduce those, if there is any alternate method?

I will give my answer based on the hypothesis, that the inputs are dependent on each other. Or let's call it interdependent.

If you are looking at your code, you'll notice that your conditions can be abstracted by basic binary calculations.

So let's assume we speak about two states:

isset = 1,
!isset = 0

And each input can have one of the two states.

If you have 1 input, then you can have 2exp(1) = 2 possibilities.

0
1

If you have 2 inputs, then you can have 2exp(2) = 4 possibilities. Nota bene: each column represents the states that an input can take in dependence with the other one.

00
01
10
11

If you have 3 inputs, then you can have 2exp(3) = 8 possibilities.

000
001
010
011
100
101
110
111

...

If you have 6 inputs, then you can have 2exp(6) = 64 states in total.

000000
000001
...
111110
111111

The general formula is:

N = 2exp(x)

Where:
N = total number of possibilities;
x: Number of observable elements, each can achieve 2 states (0 or 1).

So, as you see, it's hard to maintain such a structure. And take into consideration that you'll probably need to make validations on empty() values too. At least.

I recommend you, that you really change something in your code, so that your inputs are not anymore so dependable on each other.

So, my answer would be "no", there is no way to do it, better than you already do it. The if-elseif-else is the proper one. But that doesn't help you a lot if you have more than, let's say 3 interdependent inputs.

EDIT 1:

One relative maintainable solution would be to divide the interdependent inputs in groups of maximum 3. And only for these 3 to send a request to the server.

EDIT 2:

Or to ensure that in one request moment, only one input has been set or have a value.

Or to ensure that each of the inputs have at least a default value (like '0') on the request moment.

$query = "some query";
foreach($_POST as $key => $post){
  switch($key){
    case 1:
     $query .= " AND some condition";
    break;
    case 2:
     $query .= " AND some condition";
    break;
  }
}
mysqli_query($sql,$query);

an example for four conditions:

<?php
$c = 0;
//basic conditions...............
if( isset($_POST['input_1'] ) $c += 1; //set 1st bit
if( isset($_POST['input_2'] ) $c += 2; //set 2nd bit
if( isset($_POST['input_3'] ) $c += 4; //set 3rd bit
if( isset($_POST['input_4'] ) $c += 8; //set 4th bit

//additional conditions...............
if($c < 8){ //0..7
    if($c < 4){ //0..3
        if($c < 2){ //0..1
            if($c == 0){        //nothing set
            }else{ // 1         //input_1
            }
        }else{ //2..3
            if($c == 2){        //input_2 
            }else{ //3          //input_1 input_2
            }   
        }
    }else{ //4..7
        if($c < 6){//4..5
            if($c == 4){        //input_3
            }else{ // 5         //input_1 input_3
            }
        }else{//6..7
            if($c == 6) {       //input_2 input_3
            }else{ // 7         //input_1 input_2 input_3
            }   
        }
    }
}else{ //8..15
    if($c < 12){ //8..11
        if($c < 10){ //8..9
            if($c == 8){        //input_4
            }else{ // 9         //input_1 input_4
            }
        }else{ //10..11
            if($c == 10){       //input_2 input_4
            }else{ //11         //input_1 input_2 input_4
            }   
        }
    }else{ //12..15
        if($c < 14){//12..13
            if($c == 12){       //input_3 input_4
            }else{ // 13        //input_1 input_3 input_4
            }
        }else{//14..15
            if($c == 14) {      //input_2 input_3 input_4 
            }else{ // 15        //input_1 input_2 input_3 input_4
            }   
        }
    }   
}
?>

In this case we have to check 8 condition to get all the issets states. So it could not be the optimal solution when we have only 4 parameters what produces only 2^4=16 possibilities.

But if we take 6 arguments: Then we have to check 6 basic onditions and 6 additionals. So it gives 12 conditions to check when there is 2^6=64 possibilites.

Lets take 7 args: Then we have 7 + 7 = 14 condition to check to get one of 2^7=128 possibilities. And now we start to see advantages for bigger amount of arguments.