PHPackages                             adamb/navigation - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. adamb/navigation

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

adamb/navigation
================

Creates a navigation menu from a multi-dimentional array

1.3.7(1y ago)283MITPHP

Since Oct 8Pushed 1y ago1 watchersCompare

[ Source](https://github.com/adambinnersley/Navigation)[ Packagist](https://packagist.org/packages/adamb/navigation)[ RSS](/packages/adamb-navigation/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

Navigation
==========

[](#navigation)

Creates a HTML navigation menu and Breadcrumb menu from a PHP array

Installation
------------

[](#installation)

Installation is available via [Composer/Packagist](https://packagist.org/packages/adamb/navigation), you can add the following line to your `composer.json` file:

```
"adamb/navigation": "^1.0"
```

or

```
composer require adamb/navigation
```

Features
--------

[](#features)

- Build HTML navigation from PHP array
- Can build multi-dimensional menus from multi-dimensional arrays
- Create breadcrumb menus
- Customisable HTML classes
- Change the current selected item (if not the current page)

License
-------

[](#license)

This software is distributed under the [MIT](https://github.com/AdamB7586/Navigation/blob/master/LICENSE) license. Please read LICENSE for information on the software availability and distribution.

Usage
-----

[](#usage)

Menus and breadcrumbs can be created from either simple arrays or multi-dimensional arrays

### Basic Navigation Menu

[](#basic-navigation-menu)

#### PHP Code

[](#php-code)

```
require 'src/navigation.php';

use Nav\Navigation;

$menu = array(
    'Home' => '/',
    'Link Text' => '/link-2',
    'Sample' => '/sample',
    'Another Page' => '/yet-another-link',
    'Google' => 'https://www.google.co.uk',
    'Final Link' => '/final-page',
);

// For this example we are saying we are on the home page of the website
// You should use something like $_SERVER['REQUEST_URI'] or filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL)
$currentURI = '/';

$navigation = new Navigation($menu, $currentURI);
echo($navigation->createNavigation());
```

#### Output

[](#output)

```

        Home
        Link Text
        Sample
        Another Page
        Google
        Final Link

```

### Multi Level Navigation Menu

[](#multi-level-navigation-menu)

#### PHP Code

[](#php-code-1)

```
require 'src/navigation.php';

use Nav\Navigation;

$menu = array(
    'Home' => '/',
    'Link Text' => '/link-2',
    'Sample Submenu' => '/sample',
    array(
        'Sub item 1' => '/sub-pages/subpage1',
        'Sub item 2' => '/sub-pages/subpage2',
        'Has another level' => '/sub-pages/has-sub-pages',
        array(
            'Final Level' => '/sub-sub-pages/final-sub-level',
            'Hello World' => '/sub-sub-pages/hello-world',
        ),
    ),
    'Another Page' => '/yet-another-link',
    'Google' => 'https://www.google.co.uk',
    'Final Link' => '/final-page',
);

$currentURI = '/sub-sub-pages/hello-world'; // $_SERVER['REQUEST_URI']

$navigation = new Navigation($menu, $currentURI);
echo($navigation->createNavigation());
```

#### Output

[](#output-1)

```

    Home
    Link Text
    Sample Submenu

            Sub item 1
            Sub item 2
            Has another level

                    Final Level
                    Hello World

    Another Page
    Google
    Final Link

```

### Breadcrumb menu

[](#breadcrumb-menu)

#### PHP Code

[](#php-code-2)

```
require 'src/navigation.php';

use Nav\Navigation;

$menu = array(
    'Home' => '/',
    'Link Text' => '/link-2',
    'Sample Submenu' => '/sample',
    array(
        'Sub item 1' => '/sub-pages/subpage1',
        'Sub item 2' => '/sub-pages/subpage2',
        'Has another level' => '/sub-pages/has-sub-pages',
        array(
            'Final Level' => '/sub-sub-pages/final-sub-level',
            'Hello World' => '/sub-sub-pages/hello-world',
        ),
    ),
    'Another Page' => '/yet-another-link',
    'Google' => 'https://www.google.co.uk',
    'Final Link' => '/final-page',
);

$currentURI = '/sub-sub-pages/hello-world'; // $_SERVER['REQUEST_URI']

$navigation = new Navigation($menu, $currentURI);

// Example 1
echo($navigation->createBreadcrumb());

// Example 2
echo($navigation->setBreadcrumbElement('ol')->createBreadcrumb(true, 'my-bc-class', 'bc-item'));

// Example 3
echo($navigation->setBreadcrumbElement('nav')->createBreadcrumb());

// Example 4
echo($navigation->createBreadcrumb(false));
```

#### Output

[](#output-2)

```
// Example 1

    Home
    Sample Submenu
    Has another level
    Hello World

// Exmaple 2

    Home
    Sample Submenu
    Has another level
    Hello World

// Example 3

    Home
    Sample Submenu
    Has another level
    Hello World

// Example 4
Home &gt; Sample Submenu &gt; Has another level &gt; Hello World
```

### Change HTML Classes/Navigation ID

[](#change-html-classesnavigation-id)

You can change the default class elements on the navigation and breadcrumb items by using the following commands

#### PHP Code

[](#php-code-3)

```
require 'src/navigation.php';

use Nav\Navigation;

$menu = array(
    'Home' => '/',
    'Link Text' => '/link-2',
    'Sample Submenu' => '/sample',
    array(
        'Sub item 1' => '/sub-pages/subpage1',
        'Sub item 2' => '/sub-pages/subpage2',
        'Has another level' => '/sub-pages/has-sub-pages',
        array(
            'Final Level' => '/sub-sub-pages/final-sub-level',
            'Hello World' => '/sub-sub-pages/hello-world',
        ),
    ),
    'Another Page' => '/yet-another-link',
);

$navigation = new Navigation($menu, '/sub-sub-pages/hello-world');
$navigation->setActiveClass('current-item c-item')
           ->setNavigationClass('my-nav-class')
           ->setNavigationID('my-unique-navigation-id')
           ->setDropDownClass('my-drop-down-class drop-down');
echo($navigation->createNavigation());
```

#### Output

[](#output-3)

```

    Home
    Link Text
    Sample Submenu

            Sub item 1
            Sub item 2
            Has another level

                    Final Level
                    Hello World

    Another Page

```

### Additional Features

[](#additional-features)

You can also choose to display only a given number of navigation levels starting at any level you choose

#### PHP Code

[](#php-code-4)

```
require 'src/navigation.php';

use Nav\Navigation;

$menu = array(
    'Home' => '/',
    'Link Text' => '/link-2',
    'Sample Submenu' => '/sample',
    array(
        'Sub item 1' => '/sub-pages/subpage1',
        'Sub item 2' => '/sub-pages/subpage2',
        'Has another level' => '/sub-pages/has-sub-pages',
        array(
            'Final Level' => '/sub-sub-pages/final-sub-level',
            'Hello World' => '/sub-sub-pages/hello-world',
        ),
    ),
    'Another Page' => '/yet-another-link',
    'Google' => 'https://www.google.co.uk',
    'Final Link' => '/final-page',
);

$navigation = new Navigation($menu, '/sub-sub-pages/hello-world');

// Example 1
$levels = 1;

echo($navigation->createNavigation($levels));

// Example 2
$levels = 2;
$start_level = 1;

echo($navigation->createNavigation($levels, $start_level));
```

#### Output

[](#output-4)

```
// Example 1
// Only displays the top menu level

    Home
    Link Text
    Sample Submenu
    Another Page
    Google
    Final Link

// Example 2
// Display 2 levels of the navigation starting at level 1 (the first sub level of the current item)

    Sub item 1
    Sub item 2
    Has another level

            Final Level
            Hello World

```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1459 days

Total

2

Last Release

585d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1990042?v=4)[Adam Binnersley](/maintainers/AdamBinnersley)[@adambinnersley](https://github.com/adambinnersley)

---

Top Contributors

[![adambinnersley](https://avatars.githubusercontent.com/u/1990042?v=4)](https://github.com/adambinnersley "adambinnersley (59 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/adamb-navigation/health.svg)

```
[![Health](https://phpackages.com/badges/adamb-navigation/health.svg)](https://phpackages.com/packages/adamb-navigation)
```

###  Alternatives

[elevate-digital/nova-charcounted-fields

Text and textarea fields with a character counter.

19110.9k](/packages/elevate-digital-nova-charcounted-fields)[lummy/laravel-vue-api-crud-generator

Creates a basic skeleton for a CRUD app in both Laravel &amp; Vue.js single file components.

163.0k](/packages/lummy-laravel-vue-api-crud-generator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
