rslnerd Posted May 15, 2009 Share Posted May 15, 2009 Sorry if I sound like a total idiot, but I don't know how to do this I have a bunch of array variables that I need to access based on an inputted value. It's a dropdown menu, so the values are predetermined. For example: <?php $var1 = array("blah1","blah2","blah3","blah4"); $var2 = array("foo1","foo2","foo3","foo4"); $var3 = array("nothing1","nothing2","nothing3","nothing4"); ?> <form method="get" action="this.php" name="this"> <select> <option value="var1">1</option> <option value="var2">2</option> <option value="var3">3</option> </select> </form> So I want it so that if the user selects option 1, var1 can be accessed and i can use the array to do the calculation needed... How can I use the value to access the variable? Link to comment https://forums.phpfreaks.com/topic/158262-find-variable-based-on-inputted-value/ Share on other sites More sharing options...
Dathremar Posted May 15, 2009 Share Posted May 15, 2009 <?php if (isset($select_var)) { switch($select_var) case 1: $var_array = array("blah1","blah2","blah3","blah4"); break; case 2: $var_array = array("foo1","foo2","foo3","foo4"); break; case 3: $var_array = array("nothing1","nothing2","nothing3","nothing4"); break; } // do what ever you want with $var_array ?> <select name='select_var'> <option value="var1">1</option> <option value="var2">2</option> <option value="var3">3</option> </select> Think this will help Link to comment https://forums.phpfreaks.com/topic/158262-find-variable-based-on-inputted-value/#findComment-834687 Share on other sites More sharing options...
rslnerd Posted May 15, 2009 Author Share Posted May 15, 2009 Thanks! I've never used switch before, so I wouldn't have thought of that... Thanks a ton! Link to comment https://forums.phpfreaks.com/topic/158262-find-variable-based-on-inputted-value/#findComment-834692 Share on other sites More sharing options...
.josh Posted May 15, 2009 Share Posted May 15, 2009 alternatively... <?php $var[1] = array("blah1","blah2","blah3","blah4"); $var[2] = array("foo1","foo2","foo3","foo4"); $var[3] = array("nothing1","nothing2","nothing3","nothing4"); // example: print_r($var[$_GET['this']]); ?> <form method="get" action="this.php" name="this"> <select> <option value="var1">1</option> <option value="var2">2</option> <option value="var3">3</option> </select> </form> Link to comment https://forums.phpfreaks.com/topic/158262-find-variable-based-on-inputted-value/#findComment-834719 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.