Omzy Posted March 29, 2009 Share Posted March 29, 2009 I'm creating a form and want some drop down boxes generated from an array: I want to do something like this: $attributes=array( 'location'=>array('manchester'=>'Manchester', 'london'=>'London'), ); Essentially what I want the code to do is output the following: <select name="location"> <option value="manchester">Manchester</option> <option value="london">London</option> </select> I've got the code to match on the outer array but I now need a foreach loop which will output the values from the inner array. I want to do this using one main array ($attributes) only. Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted March 29, 2009 Share Posted March 29, 2009 http://us.php.net/foreach Quote Link to comment Share on other sites More sharing options...
Omzy Posted March 29, 2009 Author Share Posted March 29, 2009 I managed to figure it out (no thanks to "genericnumber1")... foreach($attributes as $key1 => $value1) { echo '<select name="'.$key1.'">'; foreach($value1 as $key2 => $value2) { echo '<option value="'.$key2.'">'.$value2.'</option>'; } echo '</select>'; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.