clarence/matrix

Matrix -- a simple way to write fluent codes handing 2D data -- handling array of array is so easy!

v1.0.0 2016-05-25 10:02 UTC

This package is not auto-updated.

Last update: 2024-04-13 16:56:41 UTC


README

Matrix - yet another tool for operating arrays, especially two-dimensional arrays.

Usage

Provided a data source containing two columns - productId and productName, if only rows whose productId is bigger than 5 are needed, and if a key-value structure (key is productName) is needed, it can be solved like this:

$data = Matrix::from($dataSource)
      ->select(array('productId' => 'id', 'productName'))
      ->where(function ($row) {
          return $row['id'] > 5;
      })
      ->orderBy('id', SORT_DESC)
      ->indexedBy('productName')
      ->toArray();