julian9876 Posted May 17, 2011 Share Posted May 17, 2011 hello.... I'm stuck... I'm trying to populate a check box with a 2d array. I have made three arrays within one array, but when i run it, nothing appears.. here is the code i have used so far: <legend>Optional extras</legend> <optgroup label="Entertainment"> <?php foreach($car_extras as $car_extras_id => $extras) { echo '.$car_extras_id.'; { foreach($extras as $entertainment) $i++; echo '<input type=checkbox name="options" value="'.$extras.'" id="entertainment'.$num[$i].'"/>'; echo '<label for ="entertainment'.$num[$i].'">'.$entertainment.'</label><br/>'; } } ?> This is the array code $car_extras = array ("Entertainment"=>array("6 disc DVD changer", "TV function", "DAB digital radio", "Loudspeaker system - professional", "Multimedia navigation system"), "Communication"=>array("Universal remote control", "Voice control", "Navigation system","Head-up display"), "Safety & Security"=>array("Adaptive headlights", "Night vision with pedestrian recognition", "Run-flat tyres")); Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/236649-help-with-checkboxs-with-2d-array/ Share on other sites More sharing options...
wildteen88 Posted May 17, 2011 Share Posted May 17, 2011 The <optgroup> tag is to be used within a <select> list only, eg <select> <optgroup label="Swedish Cars"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> </optgroup> <optgroup label="German Cars"> <option value="mercedes">Mercedes</option> <option value="audi">Audi</option> </optgroup> </select> You probably want to use a div or fieldset/legend tags maybe? Quote Link to comment https://forums.phpfreaks.com/topic/236649-help-with-checkboxs-with-2d-array/#findComment-1216566 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.