Dette ligner det, du leder efter
$array = array() ;
while ($row = PDO::fetchAll()) // Replace with relevant Information
{
$section = array();
$items = array();
$prices = array();
if(!array_key_exists($row['MenuId'], $array))
{
$array[$row['MenuId']] = array();
$array[$row['MenuId']]['MenuName'] = $row['MenuName'] ;
$array[$row['MenuId']]['MenuId'] = $row['MenuId'] ;
$array[$row['MenuId']]['Section'] = array();
}
if(!array_key_exists($row['SectionId'], $array[$row['MenuId']]['Section']))
{
$array[$row['MenuId']]['Section'][$row['SectionId']] = array();
$array[$row['MenuId']]['Section'][$row['SectionId']]['SectionId'] = $row['SectionId'] ;
$array[$row['MenuId']]['Section'][$row['SectionId']]['SubmenuName'] = $row['SubmenuName'] ;
$array[$row['MenuId']]['Section'][$row['SectionId']]['Items'] = array() ;
}
$items['ItemName'] = $row['ItemName'] ;
$items['Description'] = $row['Description'] ;
$prices['PriceId'] = $row['PriceId'] ;
$prices['Price'] = $row['Price'] ;
$items['Prices'] = $prices ;
$section['Items'] = $items ;
$array[$row['MenuId']]['Section'][$row['SectionId']]['Items'][] = $items ;
}
var_dump($array);
Med kun små ændringer kan du gøre det, som du vil