Created
February 21, 2013 06:36
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Test what gets returned from <select multiple> 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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