定制 ishworkh/multi-level-array-iterator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ishworkh/multi-level-array-iterator

Composer 安装命令:

composer require ishworkh/multi-level-array-iterator

包简介

Provides a way to loop through nested arrays with any depth

README 文档

README

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.

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.

ArrayElementInterface provides

  1. getValue():mixed
  2. getKeyHierarchy():KeyHierarchyInterface
    • getParentKey(int $parentLevel): string
    • getHierarchyLevel(): int

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.

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.

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

统计信息

  • 总下载量: 8k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-12-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固