Menu

How to Get Values From Multiselect Dropdown in PHP

PHP By Dec 24, 2013 No Comments

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>Pizza</option>
<option>Burger</option>
<option>Pasta</option>
<option>Chopsy</option>
<option>Soup</option>
<option>Chowmein</option>
<option>Aaloo ka Paratha</option>
</select>

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 ~~~~

Author

Hello i am Vivek Moyal PHP developer and writes tutorials for students and beginners. Love to explore new cities

No Comments

Leave a comment

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