I have a dropdown list which have some elements.
I want to get all the elements of the dropdown list into a variable of type array.
Any Idea???
How to get all elements of a dropdown list into a variable o
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: How to get all elements of a dropdown list into a variab
The square brackets indicate that the values from the select element will be available as an array
To access the values
Code: Select all
<select name="listOfItems[]">
<option value="1">One</option>
<option value="2">Two</option>
</select>
Code: Select all
<?php
if (is_array($_POST['listOfItems'])) {
foreach ($_POST['listOfItems'] as $value) {
echo $value;
}
}
?>“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering