2017 © Pedro Peláez
 

library multi-level-array-iterator

Provides a way to loop through nested arrays with any depth

image

ishworkh/multi-level-array-iterator

Provides a way to loop through nested arrays with any depth

  • Saturday, February 18, 2017
  • by Ishworkh
  • Repository
  • 1 Watchers
  • 0 Stars
  • 17 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

(PHP) Multi Level Array Iterator

There are times when there is a need to iterate over an array being unknown about the level of nested array it contains. Multi Level Array Iterator lets u do that. This functionality supports associative array and is properly tested., (*1)

Basic Usage

$array = [
    1,
    2,
    [
        3,
        4
    ],
    [
        5,
        6,
        [
            7,
            8
        ]
    ],
    [
        9,
        [
            [
                10
            ]
        ],
        11
    ]
];

foreach(\ArrayIterator\ArrayIteratorFacade::iterate($array) as $key => $ArrayItem)
{
    echo $key . ' - ' . $ArrayItem->getValue() . "\n";
}

Result:
    0 - 1
    1 - 2
    0 - 3
    1 - 4
    0 - 5
    1 - 6
    0 - 7
    1 - 8
    0 - 9
    0 - 10
    2 - 11

\ArrayIterator\ArrayIteratorFacade::iterate($array) returns a generator of ArrayElementInterface., (*2)

ArrayElementInterface provides 1. getValue():mixed 2. getKeyHierarchy():KeyHierarchyInterface - getParentKey(int $parentLevel): string - getHierarchyLevel(): int, (*3)

New instance of \ArrayIterator\Iterator\ArrayIterator can be created with \ArrayIterator\ArrayIteratorFactory which is accessible through \ArrayIterator\ArrayIteratorLocator. Both the facade or locator way can be used to get an instance of ArrayIterator., (*4)

It includes special support for laravel framework. For its integration with Laravel's dependency injection container \ArrayIterator\ArrayIteratorServiceProvider is available which can be included in the lists of service providers in config/app.php. After this, type hinting \ArrayIterator\ArrayIteratorFactory anywhere inside laravel app will resolve into \ArrayIterator\ArrayIteratorFactory properly., (*5)

Note: - For debugging purpose, echoing KeyHierarchyInterface prints out string representation of keys hierarchy starting from root array separated by '-'. - Upgraded to php7, (*6)

The Versions

18/02 2017

dev-master

9999999-dev

Provides a way to loop through nested arrays with any depth

  Sources   Download

MIT

The Requires

  • php >=7.0

 

by Ishwor Khadka

laravel php array iterator recursive multi-level

18/02 2017

v2.0.0

2.0.0.0

Provides a way to loop through nested arrays with any depth

  Sources   Download

MIT

The Requires

  • php >=7.0

 

by Ishwor Khadka

laravel php array iterator recursive multi-level

26/12 2016

v1.3.0

1.3.0.0

Provides a way to loop through nested arrays with any depth

  Sources   Download

MIT

The Requires

  • php >=5.5

 

by Ishwor Khadka

laravel php array iterator recursive multi-level

14/12 2016

v1.2.1

1.2.1.0

Provides a way to loop through nested arrays with any depth

  Sources   Download

MIT

The Requires

  • php >=5.5

 

by Ishwor Khadka

php array iterator recursive multi-level

14/12 2016

v1.2.0

1.2.0.0

Provides a way to loop through nested arrays with any depth

  Sources   Download

MIT

The Requires

  • php ^5.5 || ^7.0

 

by Ishwor Khadka

php array iterator recursive multi-level

11/12 2016

1.1.0

1.1.0.0

Provides a way to loop through nested arrays with any depth

  Sources   Download

by Ishwor Khadka

php array iterator multi-level

09/12 2016

1.0.0

1.0.0.0

Provides a way to loop through nested arrays with any depth

  Sources   Download

by Ishwor Khadka

php array iterator multi-level