tebru/multi-array
Composer 安装命令:
composer require tebru/multi-array
包简介
Provides a data structure to ease access to multidimensional arrays in PHP
README 文档
README
MultiArray
This project aims to provide easier access to multidimensional arrays. Json responses were in mind during the creation. The goal is to make it easier to check if keys are set multiple levels deep, and retrieve the value.
Installation
composer require tebru/multi-array:~0.1
Usage
Create the object by either instantiating it or using the factory. i Pass in a json object or array. An InvalidArgumentException will be thrown if it can't decode the json, or the variable isn't an array.
$array = [
'key' => 'value',
'key2' => ['nested-key' => 'value2'],
];
$multiArray = new MultiArray($array);
$multiArray = $multiArrayFactory->make($array);
$json = json_encode($array);
$multiArray = new MultiArray($json);
$multiArray = $multiArrayFactory->make($json);
From here you can check if a key exists
$multiArray->exists('key2.nested-key'); // returns true
$multiArray->exists('key3'); // returns false
Get the value of a key
$multiArray->get('key2'); // returns ['nested-key' => 'value2']
$multiArray->get('key2.nested-key'); // returns 'value2'
$multiArray->get('key3'); // throws OutOfBoundsException
Set the value of a key
$multiArray->set('key1', 'value');
$multiArray->set('key2.nested-key', 'value');
$multiArray->set('key2.newKey', 'value');
$multiArray->set('key1.newKey', 'value'); // throws InvalidArgumentException
Remove the value of a key
$multiArray->remove('key1');
$multiArray->remove('key2.unknown'); // throws OutOfBoundsException
We default to delimiting keys by a period ., but that can be changed during instantiation
$multiArray = new MultiArray($array, ':');
$multiArray = $multiArrayFactory->make($array, '--');
You can also access the object like a normal array
isset($multiArray['key2.nested-key']);
$multiArray['key2.nested-key'];
$multiArray['key2.nested-key'] = 'value';
unset($multiArray['key2.nested-key']);
tebru/multi-array 适用场景与选型建议
tebru/multi-array 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.29k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2014 年 11 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tebru/multi-array 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tebru/multi-array 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3.29k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-11-22