Skip to content

Instantly share code, notes, and snippets.

@tamouse
Created February 21, 2013 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamouse/5002728 to your computer and use it in GitHub Desktop.
Save tamouse/5002728 to your computer and use it in GitHub Desktop.
compare multiple select using an array [] as the select name and a scalar as the select name. The first returns the multiple values chosen. the latter only returns one of the values selected.
<h1>Test what gets returned from &lt;select multiple&gt; when using array and scalar</h1>
<?php
if (count($_POST)>0) {
echo "<h2>POST</h2><pre><code>\n";
var_dump($_POST);
echo "</code></pre>\n";
}
?>
<form method="POST">
<h3>Select multiple options, send as an array</h3>
<select name="group_one[]" multiple>
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
<option value="4">four</option>
</select>
<h3>Select multiple options, send as a single value</h3>
<select name="group_two" multiple>
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
<option value="4">four</option>
</select>
<input type="submit" name="submit" value="submit" />
</form>
In this case, I selected the same items in each <select> field.
POST
array(3) {
["group_one"]=>
array(3) {
[0]=>
string(1) "1"
[1]=>
string(1) "2"
[2]=>
string(1) "4"
}
["group_two"]=>
string(1) "4"
["submit"]=>
string(6) "submit"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment