I have nested array (3d) and would like to put its values in drop down select menu using PHP and jQuery
I have made some try but works only for two level arrays like (categories, sub-categories) but what if each or some of sub-categories also have more sub divisions and here is an example
$categories = array(
'fruits' => array(
'red' => array('one', 'two', 'three'),
'yellow' => array('four', 'five', 'six'),
'black' => array('seven', 'eight', 'nein'),
),
'vegetables' => array(
'blue' => array('een', 'twee', 'drie'),
'white' => array('vier', 'funf', 'zex'),
'mongo' => array('zibn', 'acht', 'noun'),
)
);
what i want to do are to show the main categoties (fruits,vegetables)
<select name="food">
<?php foreach ($categories as $category): ?>
<option value="<?php echo $category; ?>"><?php echo $category; ?></option>
<?php endforeach;?>
</select>
and on select (change) any will show select options of the sub-categories of the category i have select
and then on select any of the subcategories, it will show its sub sub categories.
<select><option></option></select>once i choose any of main categories it will show another select option to choose sub-categoroy and once i choose sub category it show another select option for the sub sub categoryhttps://i.sstatic.net/LL9gL.png