How to Get Values From Multiselect Dropdown in PHP

By | December 24, 2013

Multiselect Dropdown in PHP

Hello friends today i am going to write the script for how to get values from multiselect dropdown in PHP. Many times we need this but most of the time what we got is the last selected values. So today we will remove this problem from your project and you can easily can do what you want to do.  😆

Multiselect Dropdown

<select id="food" name="food[]" multiple="multiple">
<option>Aaloo ka Paratha</option>

This is the same Dropdown list with a slight difference we use the multiple for multiselect and important thing is we have added [] to the dropdown name ie food[].

Get values from multiselect dropdown.

Very simple code and the same code which we use always. There is no difference in your code but here we will add some more lines with the code.

$name= $_GET["food"]; -> It will get all the values
foreach ($name as $value)
echo $value.", ";

If you run this code you will find that $value is having all the selected values and you can do whatever you want to do with these values. If you want the values than just use the $value.

May be you like the article about Multiselect Dropdown and if you have any issue than please comment

~~~~ Happy Coding ~~~~

Leave a Reply

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