How to get multiple selected values of select box in PHP?

Spread the love

Sometimes, we want to get multiple selected values of select box in PHP.

In this article, we’ll look at how to get multiple selected values of select box in PHP.

How to get multiple selected values of select box in PHP?

To get multiple selected values of select box in PHP, we can loop through all the selected options.

For instance, we write

header("Content-Type: text/plain");

foreach ($_GET["select2"] as $selectedOption) {
    echo $selectedOption . "\n";
}

to get the options from the select element with name select2 with $_GET["select2"].

We use a foreach loop to loop through all the option values, which we get from $selectedOption.

Conclusion

To get multiple selected values of select box in PHP, we can loop through all the selected options.

Leave a Reply

Your email address will not be published. Required fields are marked *