]]]]]]]]]] - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of ]]]]]]]]]].php

  1. <?php
  2. $menu = [];
  3. $ob = CIBlockSection::GetList(['left_margin' => 'asc', 'sort' => 'asc'], ['IBLOCK_ID' => 6, 'ACTIVE' => 'Y']);
  4. while ($section = $ob->GetNext()) {
  5.         if ($section['IBLOCK_SECTION_ID']) {
  6.                 $menu[$section['IBLOCK_SECTION_ID']]['_child'][$section['ID']] = $section;
  7.         } else {
  8.                 $menu[$section['ID']] = $section;
  9.         }
  10. }
  11.  
  12. ?>
  13. <ul class="menu">
  14.         <?
  15.         foreach ($menu as $item) {
  16.                 if (!$item['ID']) {
  17.                         continue;
  18.                 }
  19.  
  20.                 $current = strpos($_SERVER['REQUEST_URI'], $item['SECTION_PAGE_URL']) === 0;
  21.                 ?>
  22.                 <li><a <?
  23.                         if ($current) {
  24.                                 ?>
  25.                                 class="act"
  26.                                 <?
  27.                         }
  28.                         ?> href="<?= $item['SECTION_PAGE_URL'] ?>"><?= $item['NAME'] ?></a>
  29.                         <?
  30.                         if ($current && $item['_child']) {
  31.                                 ?>
  32.                                 <div class="menu-child">
  33.                                         <?
  34.                                         foreach ($item['_child'] as $child) {
  35.                                                 $current = strpos($_SERVER['REQUEST_URI'], $child['SECTION_PAGE_URL']) === 0;
  36.  
  37.                                                 ?>
  38.                                                 <a href="<?= $child['SECTION_PAGE_URL'] ?>"<?
  39.                                                 if ($current) {
  40.                                                         ?>
  41.                                                         class="current"
  42.                                                         <?
  43.                                                 }
  44.                                                 ?>><?= $child['NAME'] ?></a>
  45.                                                 <?
  46.                                         }
  47.                                         ?>
  48.                                 </div>
  49.                                 <?
  50.                         }
  51.                         ?>
  52.                 </li>
  53.                 <?
  54.         }
  55.         ?>
  56. </ul>
File Description
  • ]]]]]]]]]]
  • PHP Code
  • 07 Sep-2023
  • 1.14 Kb
You can Share it: