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. Link to comment https://forums.phpfreaks.com/topic/151634-solved-php-array-for-form-elements/ Share on other sites More sharing options...
genericnumber1 Posted March 29, 2009 Share Posted March 29, 2009 http://us.php.net/foreach Link to comment https://forums.phpfreaks.com/topic/151634-solved-php-array-for-form-elements/#findComment-796352 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>'; } Link to comment https://forums.phpfreaks.com/topic/151634-solved-php-array-for-form-elements/#findComment-796402 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.