clarence / matrix
Matrix -- 以简单的方式编写流畅的代码处理二维数据 -- 处理数组数组变得如此简单!
v1.0.0
2016-05-25 10:02 UTC
Requires
- php: >=5.5
Requires (Dev)
- phpunit/phpunit: 4.*
This package is not auto-updated.
Last update: 2024-09-14 19:14:44 UTC
README
Matrix - 又一款操作数组的工具,尤其适用于二维数组。
用法
提供一个包含两列数据的数据源 - productId 和 productName,如果只需要 productId 大于 5 的行,并且需要一个键值结构(键是 productName),可以这样解决
$data = Matrix::from($dataSource)
->select(array('productId' => 'id', 'productName'))
->where(function ($row) {
return $row['id'] > 5;
})
->orderBy('id', SORT_DESC)
->indexedBy('productName')
->toArray();