petrgrishin/array-map
最新稳定版本:1.4.0
Composer 安装命令:
composer require petrgrishin/array-map
包简介
The object oriented approach to working with arrays on PHP
README 文档
README
The object oriented approach to working with arrays
Installation
Add a dependency to your project's composer.json:
{
"require": {
"petrgrishin/array-map": "~1.0"
}
}
Usage examples
Map
Using keys
$array = ArrayMap::create($array) ->map(function ($value, $key) { return array($key => $value); }) ->getArray();
Simple
$array = ArrayMap::create($array) ->map(function ($value) { return $value; }) ->getArray();
Merge
Recursive merge
$array = ArrayMap::create($array) ->mergeWith(array( 1 => 1, 2 => 2, 3 => array( 1 => 1, 2 => 2, ), )) ->getArray();
One level merge
$array = ArrayMap::create($array) ->mergeWith(array( 1 => 1, 2 => 2, ), false) ->getArray();
Filtering
$array = ArrayMap::create($array) ->filter(function ($value, $key) { return $value > 10 && $key > 2; }) ->getArray();
User sort
Sort by value
$array = ArrayMap::create($array) ->userSortByValue(function ($first, $second) { return $first < $second ? -1 : 1; }) ->getArray();
Sort by key
$array = ArrayMap::create($array) ->userSortByKey(function ($first, $second) { return $first < $second ? -1 : 1; }) ->getArray();
Example of use
ArrayAccess class, multi array access — https://github.com/petrgrishin/array-access
统计信息
- 总下载量: 5.79k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 2
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-06-01