php - html form option value as part of $_POST or $_GET multidimensional array? -


i'm trying setup simple dropdown menu echoes value of array corresponding option value submitted via $_get.

i don't understand how use 1 if construct using variables in multidimensional array. easy type many if constructs needed, there has way via $_get['selectname'][$n]

what doing wrong?

$animal = array("cat", "dog", "fish", "bear");      //generates dropdown menu of animals option value of 1-4 echo "<form method=\"get\"><select name=\"animaltype\">"; for($n = 0; $n < 4; $n++) {     echo "<option value=\"$n\">$animal[$n]</option>"; } echo "</select><input type=\"submit\"></form>";  //use variables in multidimensional array use 1 if construct instead of many if(isset($_get['animaltype'][$n])) {     echo $animal[$n]; } 

if want show animal select, can do:

if(isset($_get['animaltype'])) {     echo $animal[$_get['animaltype']]; } 

$_get['animaltype'] not array, string contains value of selected option.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -