ArrayBox is a PHP helper library that makes easy to manipulate the array.
PHP 5.6+ and Composer are required.
Require this package with composer using the following command.
composer require aiiro/array-box
After Composer requiring, you need to require Composer's autoload.php.
<?php
require 'vendor/autoload.php';
- sort2Dimensional - Sort two-dimensional array using the given $first, $second parameter.
- duplicatesInMultiDimensional - Find duplications in multi dimensional array.
- add - Add passed value to the instance $values variable.
- between - Retrieve the values within the given range.
- except - Retrieve the values except for the given value.
- only - Retrieve only the specified value in array.
<?php
$data = [
['volume' => 67, 'edition' => 2],
['volume' => 86, 'edition' => 1],
['volume' => 85, 'edition' => 6],
['volume' => 98, 'edition' => 1],
['volume' => 86, 'edition' => 3],
['volume' => 86, 'edition' => 2],
['volume' => 67, 'edition' => 7],
];
$array_box = new \ArrayBox\ArrayBox($data);
$sorted = $array_box->sort2Dimensional('volume', SORT_DESC, 'edition', SORT_ASC);
// Result
[
['volume' => 98, 'edition' => 1],
['volume' => 86, 'edition' => 1],
['volume' => 86, 'edition' => 2],
['volume' => 86, 'edition' => 3],
['volume' => 85, 'edition' => 6],
['volume' => 67, 'edition' => 2],
['volume' => 67, 'edition' => 7],
];
ArrayBox is released under MIT License. See MIT License for the detail.