babyshandy
1/27/2015 - 7:13 PM

How to deal with multiple values of <select> in PHP? If there are multiple values with the same KEY, how to retrieve them from $_POST in PHP

How to deal with multiple values of in PHP? If there are multiple values with the same KEY, how to retrieve them from $_POST in PHP?

http://stackoverflow.com/questions/1452914/how-to-deal-with-multiple-values-of-select-in-php

<?php
/*
Add [] to the end of the field name.
<select multiple="multiple" name="sltColorList[]">
    <option value="1">item1</option>
    <option value="2">item2</option>
    <option value="3">item3</option>
</select>
*/

// In your $_POST array, you'll get an array of all the selected options:
print_r($_POST['sltColorList']);

// Display the array values instead of their associated numbers
foreach ($_POST['sltColorList'] as $key => $value){
	echo "{$key} = {$value}\r\n";
}
?>