/ArrayBox

ArrayBox, a simple PHP extension for array.

Primary LanguagePHPMIT LicenseMIT

ArrayBox

Circle CI

ArrayBox is a PHP helper library that makes easy to manipulate the array.

Installing

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';

Functions

\ArrayBox\ArrayBox

  • 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.

Usage

Example

<?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],
];

License

ArrayBox is released under MIT License. See MIT License for the detail.