I have a page with a few checkboxes. You can make any combination of selections.
<form action="result.php" method="post">
<p>
<label>
<input type="checkbox" name="CheckboxGroup1[]" value="choice" id="choice">
option 1
</label>
<br>
<label>
<input type="checkbox" name="CheckboxGroup1[]" value="range-all" id="range-all">
option 2
</label>
<br>
<label>
<input type="checkbox" name="CheckboxGroup1[]" value="range-two" id="range-two">
option 3
</label>
<br>
<label>
<input type="checkbox" name="CheckboxGroup1[]" value="range-two" id="range-two">
option 4
</label>
<br>
<label>
<input type="checkbox" name="CheckboxGroup1[]" value="range-other-two" id="range-other-two">
option 5
</label>
<br>
</p>
<p>
<input type="submit">
</p>
</form>
Once you submit your selection, the form takes you to the next page where it compares the array of checkbox selections against a predefined array of options.
<?php
$options = array("choice", "range-all", "range-two", "range-other-two");
$checkboxes = $_POST['CheckboxGroup1'];
$intersection = array_intersect($options, $checkboxes);
$results = print_r($intersection, true);
//these are various scenarios based on what the user could choose
$scen1var = array("choice", "range-all");
$scen1 = print_r($scen1var, true);
$scen2var = array("choice", "range-two");
$scen2 = print_r($scen2var, true);
$scen3var = array("choice", "range-other-two");
$scen3 = print_r($scen3var, true);
$scen4var = array("range-all", "range-other-two");
$scen4 = print_r($scen4var, true);
if ($results === $scen1) {
echo "choice and range all";
}
elseif ($results === $scen2) {
echo "range consumables and range both";
}
//The elseif's carry on in this manner
else {
echo "something else";
}
?>
I am having an issue now where the first "if statement" works but the elseif doesn't. also, if I change the first "if statement" to compare $results to any other $scen ie. $scen2, $scen3, it doesn't work and just jumps to the "else" part.
I have a feeling I'm not making sense, so please let me know if I could explain a little more in detail...
Also this way I'm doing this seems a little overboard. Surely there is an easier way?