Hello, i want to make a categories menu which each will have its own sub-categories and that category will have own sub-categories im trying to make with arrays but i'm not really good at it.. im trying right now with bunch if statements but is there any other method of doing this with loops or something eazier ?
<form action="" method="POST">
<?php
$category = array("Cars" => 1, "Bikes" => 2, "Phones" => 3);
$cars_category = array("Honda" => 1, "BMW" => 2, "Mercedes" => 3);
$bikes_category = array("Suzuki" => 1, "GSXR" => 2, "Yamaha" => 3);
$phones_category = array("Samsung" => 1, "iPhone" => 2, "LG" => 3);
foreach($category as $main_cat => $value) {
?>
<input type="submit" name="main_category[<?= $value ?>]" value="<?= $main_cat ?>" /><br>
<?php
}
if(isset($_POST["main_category"])) {
echo "<br>";
$categ = $_POST["main_category"];
foreach($categ as $value => $name) {
if($value == 1) {
foreach($cars_category as $cars => $value) {
?>
<input type="submit" name="sub_category[<?= $value ?>]" value="<?= $cars ?>" /><br>
<?php
}
} else if($value == 2) {
foreach($bikes_category as $bikes => $value) {
?>
<input type="submit" name="sub_category[<?= $value ?>]" value="<?= $bikes ?>" /><br>
<?php
}
} else if($value == 3) {
foreach($phones_category as $phones => $value) {
?>
<input type="submit" name="sub_category[<?= $value ?>]" value="<?= $phones ?>" /><br>
<?php
}
}
}
}
?>
</form>