yiisoft/arrays
Composer 安装命令:
composer require yiisoft/arrays
包简介
Yii Array Helper
README 文档
README
Yii Arrays
The package provides:
ArrayHelperthat has static methods to work with arrays;ArraySorterthat has static methods for sort arrays;ArrayAccessTraitprovides the implementation for \IteratorAggregate, \ArrayAccess and \Countable;ArrayableInterfaceandArrayableTraitfor use in classes who want to support customizable representation of their instances.
Requirements
- PHP 8.1 - 8.5.
Installation
composer require yiisoft/arrays
ArrayHelper usage
Array helper methods are static so usage is like the following:
$username = \Yiisoft\Arrays\ArrayHelper::getValue($_POST, 'username');
Overall the helper has the following method groups.
Getting data
- getValue
- getValueByPath
- getColumn
- getObjectVars
Setting data
- addValue
- addValueByPath
- setValue
- setValueByPath
Removing data
- remove
- removeByPath
- removeValue
Detecting array types
- isIndexed
- isAssociative
HTML encoding and decoding values
- htmlDecode
- htmlEncode
Testing against arrays
- isIn
- isSubset
Transformation
- index
- group
- filter
- map
- merge
- parametrizedMerge
- renameKey
- toArray
Other
- keyExists
- pathExists
ArraySorter usage
Array sorter has one static method which usage is like the following:
\Yiisoft\Arrays\ArraySorter::multisort($data, ['age', 'name'], [SORT_ASC, SORT_DESC]);
ArrayAccessTrait usage
ArrayAccessTrait provides the implementation for
\IteratorAggregate,
\ArrayAccess and
\Countable.
Note that ArrayAccessTrait requires the class using it contain a property named data which should be an array.
The data will be exposed by ArrayAccessTrait to support accessing the class object like an array.
Example of use:
use \Yiisoft\Arrays\ArrayAccessTrait; class OfficeClassification implements \IteratorAggregate, \ArrayAccess, \Countable { use ArrayAccessTrait; public array $data = [ 'a' => 'Class A', 'b' => 'Class B', 'c' => 'Class C', ]; } $classification = new OfficeClassification(); echo 'Count classes: ' . $classification->count() . "\n"; // 3 $iterator = $classification->getIterator(); while ($iterator->valid()) { echo $iterator->current() . "\n"; // Class A, Class B, Class C $iterator->next(); }
ArrayableInterface and ArrayableTrait usage
ArrayableInterface and its implementation ArrayableTrait intended for use in classes who want to support customizable representation of their instances.
Example of use:
use \Yiisoft\Arrays\ArrayableTrait; use \Yiisoft\Arrays\ArrayableInterface; class Car implements ArrayableInterface { use ArrayableTrait; public string $type = 'Crossover'; public string $color = 'Red'; public int $torque = 472; } $car = new Car(); $data = $car->toArray(['type', 'color']); // ['type' => 'Crossover', 'color' => 'Red']
Documentation
If you need help or have a question, the Yii Forum is a good place for that. You may also check out other Yii Community Resources.
License
The Yii Arrays is free software. It is released under the terms of the BSD License.
Please see LICENSE for more information.
Maintained by Yii Software.
Support the project
Follow updates
yiisoft/arrays 适用场景与选型建议
yiisoft/arrays 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.16M 次下载、GitHub Stars 达 56, 最近一次更新时间为 2019 年 04 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「array」 「helper」 「yii」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 yiisoft/arrays 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yiisoft/arrays 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 yiisoft/arrays 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
Datetime helpers for timezone handling
Trait providing methods to set class properties with an array.
Library with classes to help you do batch.
Traits to build collections of specific objects
统计信息
- 总下载量: 2.16M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 57
- 点击次数: 14
- 依赖项目数: 84
- 推荐数: 2
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2019-04-23