shudrum/array-finder
最新稳定版本:v1.1.0
Composer 安装命令:
composer require shudrum/array-finder
包简介
ArrayFinder component
README 文档
README
ArrayFinder Component
The ArrayFinder component allow you to manage large nested arrays with ease.
Here is a simple example that shows how to easily get a value from an array:
use Shudrum\Component\ArrayFinder\ArrayFinder; $arrayFinder = new ArrayFinder([ 'level_1' => [ 'level_2' => [ 'level_3' => 'value', ], ], ]); $myValue = $arrayFinder->get('level_1.level_2.level_3'); // OR $myValue = $arrayFinder['level_1.level_2.level_3'];
To install this package, you can simply use composer:
composer require shudrum/array-finder
Documentation
Methods
get($path)
You can get a value following a path separated by a '.'.
use Shudrum\Component\ArrayFinder\ArrayFinder; $arrayFinder = new ArrayFinder([ 'a' => [ 'b' => [ 'c' => 'value1', ], 'value2', ], 'value3', ]); $myValue = $arrayFinder->get('a.b.c'); // value1 $myValue = $arrayFinder->get('a.0'); // value2 $myValue = $arrayFinder->get(0); // value3
If the path is null, all the content will be returned.
set($path, $value)
You can add a value to a specific path separated by a '.'. If the nested arrays does not exists, it will be created.
use Shudrum\Component\ArrayFinder\ArrayFinder; $arrayFinder = new ArrayFinder(); $arrayFinder->set('a.b', 'value'); $arrayFinder->get(); // ['a' => ['b' => 'value]]
changeSeparator($separator)
If the default separator (.) does not fit to your needs, you can call this method to change it.
use Shudrum\Component\ArrayFinder\ArrayFinder; $arrayFinder = new ArrayFinder([…]); $myValue = $arrayFinder->changeSeparator('/'); $myValue = $arrayFinder->get('a/b/c');
Implementations
The ArrayFinder component implements some usefull interfaces:
ArrayAccess
You can use this object like an array:
use Shudrum\Component\ArrayFinder\ArrayFinder; $arrayFinder = new ArrayFinder([…]); $value = $arrayFinder['a.b']; $arrayFinder['a.b.c'] = 'value'; unset($arrayFinder['a.b']);
Countable
You can use count on this object:
use Shudrum\Component\ArrayFinder\ArrayFinder; $arrayFinder = new ArrayFinder([…]); count($arrayFinder); count($arrayFinder['a.b']);
Iterator
You can iterate on this object:
use Shudrum\Component\ArrayFinder\ArrayFinder; $arrayFinder = new ArrayFinder([…]); foreach ($arrayFinder as $key => $value) { // … }
Serializable
You can easily serialize / unserialize this object.
##Resources
You can run the unit tests with the following command:
$ cd path/to/Shudrum/Component/ArrayFinder/
$ composer install
$ phpunit
shudrum/array-finder 适用场景与选型建议
shudrum/array-finder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.77M 次下载、GitHub Stars 达 14, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 shudrum/array-finder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 shudrum/array-finder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.77M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 16
- 点击次数: 22
- 依赖项目数: 8
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04