Skip to content
Snippets Groups Projects

simple tree menu

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Pavel Tupikov

    simple tree menu

    Edited
    result_modifier.php 625 B
    <?
    if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();
    
    $menuList = array();
    $lev = 0;
    $lastInd = 0;
    $parents = array();
    foreach ($arResult as $arItem) {
       $lev = $arItem['DEPTH_LEVEL'];
       
       if ($arItem['IS_PARENT']) {
          $arItem['CHILDREN'] = array();
       }
       
       if ($lev == 1) {
          $menuList[] = $arItem;
          $lastInd = count($menuList)-1;
          $parents[$lev] = &$menuList[$lastInd];
       } else {
          $parents[$lev-1]['CHILDREN'][] = $arItem;
          $lastInd = count($parents[$lev-1]['CHILDREN'])-1;
          $parents[$lev] = &$parents[$lev-1]['CHILDREN'][$lastInd];
       }
    }
    $arResult = $menuList;
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment