menu_refactor - 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 menu_refactor.php

  1. <?php
  2.  
  3. $pagina = "index";
  4.  
  5. $menu = [
  6.     [
  7.         'title' => 'Home',
  8.         'url' => 'index.php'
  9.     ],
  10.     [
  11.         'title' => 'Sobre',
  12.         'url' => 'quemsomos.php'
  13.     ],
  14.     [
  15.         'title' => 'Como Consultar',
  16.         'url' => 'comoconsultar.php'
  17.     ],
  18.     [
  19.         'title' => 'Blog',
  20.         'url' => 'blog'
  21.     ],
  22.     [
  23.         'title' => 'Empresas',
  24.         'url' => 'paraempresas.php'
  25.     ],
  26.     [
  27.         'title' => 'Contrato',
  28.         'url' => 'contrato.php'
  29.     ],
  30.     [
  31.         'title' => 'Privacidade',
  32.         'url' => 'privacidade.php'
  33.     ],
  34.     [
  35.         'title' => 'Contato',
  36.         'url' => 'contato.php'
  37.     ]
  38. ];
  39. ?>
  40. <ul id="top-menu" class="nav navbar-nav navbar-right main-nav">
  41.     <?php foreach($menu as $item): ?>
  42.     <li><a href="<?php echo $item['url']; ?>" title="<?php echo $item['title']; ?>"<?php echo $pagina == str_replace('.php', '', $item['url']) ? ' class="active"' : ''; ?>><?php echo $item['title']; ?></a></li>
  43.     <?php endforeach; ?>
  44. </ul>
File Description
  • menu_refactor
  • PHP Code
  • 21 Feb-2019
  • 991 Bytes
You can Share it: