I have Menu (food) within those menus I have submenus (first, second, etc) and within submenus I have dishes.
The submenus are generated perfectly for me and as soon as the dishes are always filled with the last dishes from the last submenu id, with which he always brings out the same dishes in all the submenus even if they are different.
Crude menu:
/*SUBMENUS DE UN MENU*/
public function justSubMenu($arrayMenu,$id_menu){
$result = [];
foreach ($arrayMenu as $key => $value) {
if($value['id'] == $id_menu) {
array_push($result, $value['nombre']);
}
}
return array_unique($result);;
}
/*PLATOS DE UN SUBMENU*/
public function platosSubMenu($arrayMenu,$id_submenu){
$result = [];
foreach ($arrayMenu as $key => $value) {
if ($value[3] == $id_submenu) {
array_push($result, $value[0]);
}
}
return $result;
}
And as I show the data,
<?php
$infoMenu = $crudMenu->platosMenu($_GET['id_menu']);
$submenus = $crudMenu->justSubMenu($infoMenu,194);
foreach ($infoMenu as $key => $value) {
$info = $crudMenu->platosSubMenu($infoMenu,$infoMenu[$key][3]);
}
?>
<div class="container-fluid platos p-0 m-0">
<div class="first">
<?php foreach ($submenus as $key => $value) { ?>
<div class="cabecal row flex-parent">
<section class="col-xs-10 col-sm-10 col-md-10 col-lg-10">
<div class="cabecalTitle flex-child">
<h2><?php echo $value ?></h2>
</div>
</section>
</div>
<div class="row groupDish">
<?php foreach ($info as $key => $value) { ?>
<article class="col-xs-12 col-sm-6 col-md-6 col-lg-6 float-left">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<h3 class="nameDish"><?php echo $value; ?></h3>
</div>
<div class="price">
<span><!-- <?php // echo $value[]; ?> --></span>
</div>
</article>
<?php } ?>
</div>
<?php } ?>
<div>
</div>
What do I get from each array?
ARRAY INFOMENU
Array ( [0] => Array ( [nombre] => NOMBRE DEL SUBMENU 2 [0] => plato 1 [precio] => 0 [1] => 0 [2] => NOMBRE DEL SUBMENU 2 [id] => 194 [3] => 141 [4] => 194 ) [1] => Array ( [nombre] => NOMBRE DEL SUBMENU 2 [0] => plato 2 [precio] => 0 [1] => 0 [2] => NOMBRE DEL SUBMENU 2 [id] => 194 [3] => 141 [4] => 194 ) [2] => Array ( [nombre] => NOMBRE DEL SUBMENU [0] => plato aulacampius 2 [precio] => 0 [1] => 0 [2] => NOMBRE DEL SUBMENU [id] => 194 [3] => 140 [4] => 194 ) )
ARRAY INFO
Array ( [0] => plato aulacampius 2 )
ARRAY SUBMENUS
Array ( [0] => NOMBRE DEL SUBMENU 2 [2] => NOMBRE DEL SUBMENU )
There you have your whole problem: you are continually overwriting the array, not just saving new information. One way to fix it would be:
In this way you create an array with arrays, where each position corresponds to a submenu, with the same positions as those that the submenus have in the corresponding array, taking that into account, you can now display the data.
Hope it has fit.