lupsor/array-parser
Composer 安装命令:
composer require lupsor/array-parser
包简介
This package get data from an associative array
README 文档
README
About package
This package get data from an associative array.
Knowing the path to the data you need in the array, you can easily get it using ArrayParser, without having to iterate through the array yourself.
Содержание
Setup
To install the package, run on the command line:
composer install lupsor/array-parser
Using
To get the desired value, run:
ArrayParser::parse($data, $parserString), where $date is an array from which you want to get the value, and $parserString is a link to the received data
ParserString
Without collection
Before you get the necessary data, you need to form a link to the data you need. Example:
three->one->one, where three, one and one - are the array key, and -> is the separator.
Based on this example, the ArrayParser will refer to the array element with the key three, there it will refer to the element with the key one and it will get the value of the element with the key one.
With collection
You can also get data from the collection by wrapping the required value in square brackets ([, ]). Example:
three->[one], where [one] - collection. The parser will iterate over all the values in the element with the key "three" and from each element of the array will get the value with the key "one".
The collection can be more complex, like [one->two]. You can learn more about this structure in example No. 2 and 3.
Parse object
The first argument ArrayParser::parse ($data) can be sent as an object, in which case the path must only point to functions that require no arguments.
Examples of using
Example 1 (without collection)
use Lupsor\ArrayParser\ArrayParser; $data = [ 'one' => 'oneValue', 'three' => [ 'one' => ['one' => 'threeOneOneValue',], ], ]; $parserString = 'three->one->one'; ArrayParser::parse($data, $parserString);
The result of running this example will be: threeOneOneValue
Example 2 (with collection)
use Lupsor\ArrayParser\ArrayParser; $data = [ 'four' => [ ['one' => 'fourOneValue',], ['one' => 'fourTwoValue',], ], ]; $parserString = 'four->[one]'; ArrayParser::parse($data, $parserString);
Result: fourOneValue, fourTwoValue
Example 3 (with collection)
use Lupsor\ArrayParser\ArrayParser; $data = [ 'five' => [ [ 'one' => [ ['one' => 'fiveOneOneValue',], ['one' => 'fourOneTwoValue',], ], ], [ 'one' => [ ['one' => 'fiveTwoOneValue',], ['one' => 'fourTwoTwoValue',], ['one' => 'fourTwoThreeValue',], ], ], ], ]; $parserString = 'five->[one->[one]]'; ArrayParser::parse($data, $parserString);
Result: fiveOneOneValue, fourOneTwoValue, fiveTwoOneValue, fourTwoTwoValue, fourTwoThreeValue
Additionally
Unique values
You can return only unique values by adding :unique at the end of ParserString. Example: five->[one->[one]]:unique
lupsor/array-parser 适用场景与选型建议
lupsor/array-parser 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.67k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 05 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 lupsor/array-parser 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lupsor/array-parser 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 9.67k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-05-13