Skip to content

Instantly share code, notes, and snippets.

@Plastickid
Forked from jonesch/menu-array-loop
Created January 21, 2021 18:19
Show Gist options
  • Select an option

  • Save Plastickid/7ca29201ad9ce8f4cb9d1e6ebe82c13f to your computer and use it in GitHub Desktop.

Select an option

Save Plastickid/7ca29201ad9ce8f4cb9d1e6ebe82c13f to your computer and use it in GitHub Desktop.

Revisions

  1. @jonesch jonesch created this gist Oct 5, 2012.
    34 changes: 34 additions & 0 deletions menu-array-loop
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    //Use CSS to make these columns responsive.
    <ul class="food-menus<?=(' '.$menu_category)?>">
    <?php
    //Let's get a count of how many items we are going to display of our menu
    $total_menu_categories = count($menu[$menu_category]);
    $total_items = $total_menu_categories;
    foreach($menu[$menu_category] as $section => $value) {
    $total_items = $total_items + count($value);
    } //get the total number of <li>s on our page
    $number_of_columns = 3;
    $ul_break_point = ceil($total_items/$number_of_columns);

    //start the counting, and looping
    $counter = 0;
    foreach($menu[$menu_category] as $section => $value) {
    if($section!='general'){ //general blurb for each category still counts as one item.
    echo '<li class="title">'.str_replace('-', ' ', $section).'</li>'; $counter++;
    }
    foreach($value as $item => $details) { //each category within the menu, and all it's items
    if($item=='overview'){ //overview of sub-category
    echo '<li class="overview">'.$details.'</li>'; $counter++;
    } else { //item title, information, price, description
    echo '<li><p'.(empty($details['price'])?' class="none"':'').'>
    <span class="title">'.$item.'</span>
    <span class="price">'.$details['price'].'</span>
    </p>'.(!empty($details['description'])?$details['description']:'&nbsp;').'</li>'; $counter++;
    }
    if($counter % $ul_break_point == 0){ //when do we need to break.
    echo '</ul><ul class="food-menus '.$menu_category.'">';
    }
    }
    }
    ?>
    </ul><!-- .menus lunch-menu -->