Jump to content

Help with checkbox's with 2d array


julian9876

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/236649-help-with-checkboxs-with-2d-array/
Share on other sites

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?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.