PHPackages                             barogue/collection - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. barogue/collection

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

barogue/collection
==================

A class wrapper for PHP native arrays

0.0.2(2y ago)07mitPHPPHP &gt;=8.1

Since Aug 26Pushed 2y agoCompare

[ Source](https://github.com/barogue/collections)[ Packagist](https://packagist.org/packages/barogue/collection)[ RSS](/packages/barogue-collection/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (6)Versions (3)Used By (0)

A wrapper class for PHP native arrays
=====================================

[](#a-wrapper-class-for-php-native-arrays)

[![Tests](https://github.com/barogue/collections/workflows/quality/badge.svg)](https://github.com/barogue/collections/workflows/quality/badge.svg)[![codecov](https://camo.githubusercontent.com/8a28a4256e664de415b6592382833488f27f8665664b2eb2faaae76ca73e4207/68747470733a2f2f636f6465636f762e696f2f67682f6261726f6775652f636f6c6c656374696f6e732f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/barogue/collections)[![Licence Badge](https://camo.githubusercontent.com/6c9cb82a668257b4911d30ade84b8f937087650b77feebdb87b683452ab4ab4c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6261726f6775652f636f6c6c656374696f6e732e737667)](https://img.shields.io/github/license/barogue/collections.svg)[![Release Badge](https://camo.githubusercontent.com/2ea88881677df0c4f50028fd2dc2b8cc97a3ee0987c0ebfda7d51ebbfd8697f1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6261726f6775652f636f6c6c656374696f6e732e737667)](https://img.shields.io/github/release/barogue/collections.svg)[![Tag Badge](https://camo.githubusercontent.com/a6c5f6abb49be2c1a268fcd1660b9aacf9d25821cca5f48cf2f6da1b25d29e3f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f6261726f6775652f636f6c6c656374696f6e732e737667)](https://img.shields.io/github/tag/barogue/collections.svg)[![Issues Badge](https://camo.githubusercontent.com/100b0630e07ec76d4927253780ce72b529f919562a8ad01a2f5142096eb408e2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6261726f6775652f636f6c6c656374696f6e732e737667)](https://img.shields.io/github/issues/barogue/collections.svg)[![Code Size](https://camo.githubusercontent.com/4d196f3e931e86772fc4bcee5b10b0dae8736fd2f59c559b45fd9ed1cbce8fe7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f6261726f6775652f636f6c6c656374696f6e732e7376673f6c6162656c3d73697a65)](https://img.shields.io/github/languages/code-size/barogue/collections.svg)

A class wrapper for PHP native arrays

Compatibility and dependencies
------------------------------

[](#compatibility-and-dependencies)

This library is compatible with PHP version `8.1` and `8.2`.

This library has no dependencies.

Installation
------------

[](#installation)

Installation is simple using composer.

```
composer require barogue/collections
```

Or simply add it to your `composer.json` file

```
{
    "require": {
        "barogue/collections": "^1.0"
    }
}
```

Contributing
------------

[](#contributing)

This library follows [PSR-1](https://www.php-fig.org/psr/psr-1/) &amp; [PSR-2](https://www.php-fig.org/psr/psr-2/) standards.

#### Unit Tests

[](#unit-tests)

Before pushing any changes, please ensure the unit tests are all passing.

If possible, feel free to improve coverage in a separate commit.

```
vendor/bin/phpunit
```

#### Code sniffer

[](#code-sniffer)

Before pushing, please ensure you have run the code sniffer. **Only run it using the lowest support PHP version (8.1)**

```
vendor/bin/php-cs-fixer fix
```

#### Static Analyses

[](#static-analyses)

Before pushing, please ensure you have run the static analyses tool.

```
vendor/bin/phan
```

#### Benchmarks

[](#benchmarks)

Before pushing, please ensure you have checked the benchmarks and ensured that your code has not introduced any slowdowns.

Feel free to speed up existing code, in a separate commit.

Feel free to add more benchmarks for greater coverage, in a separate commit.

```
vendor/bin/phpbench run --report=speed
vendor/bin/phpbench run --report=speed --output=markdown
vendor/bin/phpbench run --report=speed --filter=benchNetFromTax --iterations=50 --revs=50000

vendor/bin/phpbench xdebug:profile
vendor/bin/phpbench xdebug:profile --gui
```

Documentation
-------------

[](#documentation)

This library adds a new class that can wrap around native arrays to mke interactions with them quicker and simpler.

Below you can find links to the documentation for the new features.

### Creating an instance of the collection

[](#creating-an-instance-of-the-collection)

```
use Barogue\Collections\Collection;

// Using the constructor
$collection = new Collection();
$collection = new Collection([1, 2, 3]);

// Using the chainable constructor
$collection = Collection::instance();
$collection = Collection::instance([1, 2, 3]);

// Create using a range
$celsius = Collection::range(0, 100);
$alphabet = Collection::range('a', 'z');
$evens = Collection::range(0, 100, 2);
```

### Getting data from a collection

[](#getting-data-from-a-collection)

```
use Barogue\Collections\Collection;

// Collections can be used exactly like a normal array
$collection = new Collection([1, 2, 3]);
$collection[] = 4;
$collection['test'] = 5;
echo $collection[1]; // 2

// Get the original array
$collection->getArray();

// Get an iterator
$collection->getIterator();

// Getting the size of the collection
echo count($collection); // 5
echo $collection->count(); // 5
```

### A list of native methods integrated into this class

[](#a-list-of-native-methods-integrated-into-this-class)

**[array\_change\_key\_case](https://www.php.net/manual/en/function.array-change-key-case.php)** Changes the case of all keys in an array

```
use Barogue\Collections\Collection;

$collection = new Collection(["FirSt" => 1, "SecOnd" => 4]);

$collection->changeKeyCase(CASE_UPPER); // ["FIRST" => 1, "SECOND" => 4]
$collection->changeKeyCase(CASE_LOWER); // ["first" => 1, "second" => 4]

$collection->changeKeyUpperCase(); // ["FIRST" => 1, "SECOND" => 4]
$collection->changeKeyLowerCase(); // ["first" => 1, "second" => 4]
```

**[array\_chunk](https://www.php.net/manual/en/function.array-chunk.php)** Split an array into chunks

```
use Barogue\Collections\Collection;

$collection = Collection::range(1, 100);
$chunks = $collection->chunk(10);
```

**[array\_column](https://www.php.net/manual/en/function.array-column.php)** Return the values from a single column in the input array

```
use Barogue\Collections\Collection;

$collection = new Collection([
    'player_1' => [
        'name' => 'John',
        'stats' => [
            'hp' => 50,
            'exp' => 1000
        ]
    ],
    'player_2' => [
        'name' => 'Jane',
        'stats' => [
            'hp' => 70,
            'exp' => 1000
        ]
    ]
]);
$hps = $collection->column('stats.hp'); // [50, 70]
$hps = $collection->column('stats.hp', 'name'); // ['John' => 50, 'Jane' => 70]
```

**[array\_combine](https://www.php.net/manual/en/function.array-combine.php)** Creates an array by using one array for keys and another for its values

```
use Barogue\Collections\Collection;

$keys = new Collection(['a', 'b', 'c']);
$combined = $keys->combine(1, 2, 3); // ['a' => 1, 'b' => 2, 'c' => 3]

$combined = Collection::instance(['a', 'b', 'c'])->combine(1, 2, 3); // ['a' => 1, 'b' => 2, 'c' => 3]
```

**[array\_count\_values](https://www.php.net/manual/en/function.array-count-values.php)** Counts all the values of an array

```
use Barogue\Collections\Collection;

$collection = new Collection([1, 2, 3, 1, 2, 4, 'a', 'a', 1]);

$appearances = $collection->countValues(); // [1 => 3, 2 => 2, 3 => 1, 4 => 1, 'a' => 2]
```

**[array\_diff\_assoc](https://www.php.net/manual/en/function.array-diff-assoc.php)** Computes the difference of arrays with additional index check

```
// Add documentation
```

**[array\_diff\_key](https://www.php.net/manual/en/function.array-diff-key.php)** Computes the difference of arrays using keys for comparison

```
// Add documentation
```

**[array\_diff\_uassoc](https://www.php.net/manual/en/function.array-diff-uassoc.php)** Computes the difference of arrays with additional index check which is performed by a user supplied callback function

```
// Add documentation
```

**[array\_diff\_ukey](https://www.php.net/manual/en/function.array-diff-ukey.php)** Computes the difference of arrays using a callback function on the keys for comparison

```
// Add documentation
```

**[array\_diff](https://www.php.net/manual/en/function.array-diff.php)** Computes the difference of arrays

```
use Barogue\Collections\Collection;

$collection = new Collection([1, 2, 3, 4, 5, 6]);
$diff = $collection->diff([3, 4, 5]);
$diff = $collection->diff(new Collection([3, 4, 5]));
```

**[array\_fill\_keys](https://www.php.net/manual/en/function.array-fill-keys.php)** Fill an array with values, specifying keys

```
// Add documentation
```

**[array\_fill](https://www.php.net/manual/en/function.array-fill.php)** Fill an array with values

```
// Add documentation
```

**[array\_filter](https://www.php.net/manual/en/function.array-filter.php)** Filters elements of an array using a callback function

```
use Barogue\Collections\Collection;

$collection = new Collection([1, 2, 3, 4, 5, 6, null]);

$collection->filter();
$collection->filter(function ($item) {
    return $item > 3;
});
```

**[array\_flip](https://www.php.net/manual/en/function.array-flip.php)** Exchanges all keys with their associated values in an array

```
use Barogue\Collections\Collection;

$collection = new Collection(['a', 'b', 'c']);
$flipped = $collection->flip(); // ['a' => 0, 'b' => 1, 'c' => 2]

$collection = new Collection(['a', 'b', 'c', 'a']);
$flipped = $collection->flip(); // ['a' => 0, 'b' => 1, 'c' => 2]
$doubleFlipped = $collection->flip()->flip(); // ['a' => 0, 'b' => 1, 'c' => 2]
```

**[array\_intersect\_assoc](https://www.php.net/manual/en/function.array-intersect-assoc.php)** Computes the intersection of arrays with additional index check

```
// Add documentation
```

**[array\_intersect\_key](https://www.php.net/manual/en/function.array-intersect-key.php)** Computes the intersection of arrays using keys for comparison

```
// Add documentation
```

**[array\_intersect\_uassoc](https://www.php.net/manual/en/function.array-intersect-uassoc.php)** Computes the intersection of arrays with additional index check, compares indexes by a callback function

```
// Add documentation
```

**[array\_intersect\_ukey](https://www.php.net/manual/en/function.array-intersect-ukey.php)** Computes the intersection of arrays using a callback function on the keys for comparison

```
// Add documentation
```

**[array\_intersect](https://www.php.net/manual/en/function.array-intersect.php)** Computes the intersection of arrays

```
// Add documentation
```

**[array\_is\_list](https://www.php.net/manual/en/function.array-is-list.php)** Checks whether a given array is a list

```
use Barogue\Collections\Collection;

Collection::instance(['a', 'b', 'c'])->isList(); // true
Collection::instance(['a' => 1, 'b', 'c'])->isList(); // false
```

**[array\_key\_exists](https://www.php.net/manual/en/function.array-key-exists.php)** Checks if the given key or index exists in the array

```
use Barogue\Collections\Collection;

$collection = new Collection([
    'a' => 1,
    'b' => 2,
    'c' => [
        'a' => 1,
        'b' => null,
        'c' => 3,
    ],
]);
$collection->exists('a'); // true
$collection->exists('z'); // false
$collection->exists('c.a'); // true
$collection->exists('c.b'); // true
$collection->exists('c.z'); // false
```

**[array\_key\_first](https://www.php.net/manual/en/function.array-key-first.php)** Gets the first key of an array

```
use Barogue\Collections\Collection;

$collection = new Collection([
    'a' => 1,
    'b' => 2,
    'c' => 3,
    'd' => 4,
    'e' => 5,
]);

$collection->firstKey(); // 'a'
$collection->firstKey(fn($value, $key) => $value >= 3); // 'c'
$collection->firstKey(fn($value, $key) => $key != 'a'); // 'b'
```

**[array\_key\_last](https://www.php.net/manual/en/function.array-key-last.php)** Gets the last key of an array

```
use Barogue\Collections\Collection;

$collection = new Collection([
    'a' => 1,
    'b' => 2,
    'c' => 3,
    'd' => 4,
    'e' => 5,
]);

$collection->lastKey(); // 'e'
$collection->lastKey(fn($value, $key) => $value >= 3); // 'e'
$collection->lastKey(fn($value, $key) => $key != 'a'); // 'e'
```

**[array\_keys](https://www.php.net/manual/en/function.array-keys.php)** Return all the keys or a subset of the keys of an array

```
use Barogue\Collections\Collection;

$collection = new Collection([
    'a' => 1,
    'b' => 2,
    'c' => [
        'a' => 1,
        'b' => null,
        'c' => 3,
    ],
]);

$collection->keys(); // ['a', 'b', 'c']

$collection->keys(true); // ['a', 'b', 'c.a', 'c.b', 'c.c']
```

**[array\_map](https://www.php.net/manual/en/function.array-map.php)** Applies the callback to the elements of the given arrays

```
use Barogue\Collections\Collection;

$collection = new Collection([
    'a' => 1,
    'b' => 2,
    'c' => 3
]);

$increased = $collection->map(function ($value) {
    return $value * 2;
}); // ['a' => 2, 'b' => 4, 'c' => 6]

$concatenatedKeys = $collection->map(function ($value, $key) {
    return $key.'-'.$value;
}); // ['a' => 'a-1', 'b' => 'b-2', 'c' => 'c-3']
```

**[array\_merge\_recursive](https://www.php.net/manual/en/function.array-merge-recursive.php)** Merge one or more arrays recursively

```
// Add documentation
```

**[array\_merge](https://www.php.net/manual/en/function.array-merge.php)** Merge one or more arrays

```
// Add documentation
```

**[array\_multisort](https://www.php.net/manual/en/function.array-multisort.php)** Sort multiple or multi-dimensional arrays

```
// Add documentation
```

**[array\_pad](https://www.php.net/manual/en/function.array-pad.php)** Pad array to the specified length with a value

```
// Add documentation
```

**[array\_pop](https://www.php.net/manual/en/function.array-pop.php)** Pop the element off the end of array

```
use Barogue\Collections\Collection;

$collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8]);
$single = $collection->pop(); // 8
$multiple = $collection->pop(4)->getArray(); // [7, 6, 5, 4]
```

**[array\_product](https://www.php.net/manual/en/function.array-product.php)** Calculate the product of values in an array

```
// Add documentation
```

**[array\_push](https://www.php.net/manual/en/function.array-push.php)** Push one or more elements onto the end of array

```
use Barogue\Collections\Collection;

$collection = new Collection();
$collection->push('test'); // ['test']
$collection->push(1, 2, 3, 4, 5, 6);  // ['test', 1, 2, 3, 4, 5]
```

**[array\_rand](https://www.php.net/manual/en/function.array-rand.php)** Pick one or more random keys out of an array

```
use Barogue\Collections\Collection;

$collection = new Collection([
    'a' => 1,
    'b' => 2,
    'c' => 3
]);

$collection->randomKey(); // 'b'
$collection->randomKeys(2)->getArray(); // ['c', 'a']
```

**[array\_reduce](https://www.php.net/manual/en/function.array-reduce.php)** Iteratively reduce the array to a single value using a callback function

```
use Barogue\Collections\Collection;

$factorial = Collection::range(10, 1)->reduce(fn($carry, $value) => $carry * $value, 1)
$factorial = Collection::factorial(10)
```

**[array\_replace\_recursive](https://www.php.net/manual/en/function.array-replace-recursive.php)** Replaces elements from passed arrays into the first array recursively

```
// Add documentation
```

**[array\_replace](https://www.php.net/manual/en/function.array-replace.php)** Replaces elements from passed arrays into the first array

```
// Add documentation
```

**[array\_reverse](https://www.php.net/manual/en/function.array-reverse.php)** Return an array with elements in reverse order

```
use Barogue\Collections\Collection;

$collection = new Collection([
    'a' => 1,
    'b' => 2,
    'c' => 3
]);

$reversedCopy = $collection->reverse(); // ['c' => 3, 'b' => 2, 'a' => 1]
```

**[array\_search](https://www.php.net/manual/en/function.array-search.php)** Searches the array for a given value and returns the first corresponding key if successful

```
// Add documentation
```

**[array\_shift](https://www.php.net/manual/en/function.array-shift.php)** Shift an element off the beginning of array

```
use Barogue\Collections\Collection;

$collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8]);
$single = $collection->shift(); // 1
$multiple = $collection->shift(4)->getArray(); // [2, 3, 4, 5]
```

**[array\_slice](https://www.php.net/manual/en/function.array-slice.php)** Extract a slice of the array

```
// Add documentation
```

**[array\_splice](https://www.php.net/manual/en/function.array-splice.php)** Remove a portion of the array and replace it with something else

```
// Add documentation
```

**[array\_sum](https://www.php.net/manual/en/function.array-sum.php)** Calculate the sum of values in an array

```
use Barogue\Collections\Collection;

$sum = Collection::instance([1, 2, 3])->sum(); // 6
$sum = Collection::range(1, 100)->sum(); // 5050
```

**[array\_udiff\_assoc](https://www.php.net/manual/en/function.array-udiff-assoc.php)** Computes the difference of arrays with additional index check, compares data by a callback function

```
// Add documentation
```

**[array\_udiff\_uassoc](https://www.php.net/manual/en/function.array-udiff-uassoc.php)** Computes the difference of arrays with additional index check, compares data and indexes by a callback function

```
// Add documentation
```

**[array\_udiff](https://www.php.net/manual/en/function.array-udiff.php)** Computes the difference of arrays by using a callback function for data comparison

```
// Add documentation
```

**[array\_uintersect\_assoc](https://www.php.net/manual/en/function.array-uintersect-assoc.php)** Computes the intersection of arrays with additional index check, compares data by a callback function

```
// Add documentation
```

**[array\_uintersect\_uassoc](https://www.php.net/manual/en/function.array-uintersect-uassoc.php)** Computes the intersection of arrays with additional index check, compares data and indexes by separate callback functions

```
// Add documentation
```

**[array\_uintersect](https://www.php.net/manual/en/function.array-uintersect.php)** Computes the intersection of arrays, compares data by a callback function

```
// Add documentation
```

**[array\_unique](https://www.php.net/manual/en/function.array-unique.php)** Removes duplicate values from an array

```
// Add documentation
```

**[array\_unshift](https://www.php.net/manual/en/function.array-unshift.php)** Prepend one or more elements to the beginning of an array

```
// Add documentation
```

**[array\_values](https://www.php.net/manual/en/function.array-values.php)** Return all the values of an array

```
use Barogue\Collections\Collection;

$values = Collection::instance(['a' => 1, 'b' => 2])->values()->getArray(); // [1, 2]
```

**[array\_walk\_recursive](https://www.php.net/manual/en/function.array-walk-recursive.php)** Apply a user function recursively to every member of an array

```
// Add documentation
```

**[array\_walk](https://www.php.net/manual/en/function.array-walk.php)** Apply a user supplied function to every member of an array

```
// Add documentation
```

**[arsort](https://www.php.net/manual/en/function.arsort.php)** Sort an array in descending order and maintain index association

```
use Barogue\Collections\Collection;

$collection = new Collection(['a' => 9, 'b' => 1, 'c' => 5]);
$collection->reverseSort(); // ['a' => 9, 'c' => 5, 'b' => 1]
```

**[asort](https://www.php.net/manual/en/function.asort.php)** Sort an array in ascending order and maintain index association

```
use Barogue\Collections\Collection;

$collection = new Collection(['a' => 9, 'b' => 5, 'c' => 1]);
$collection->sort(); // ['c' => 1, 'b' => 5, 'a' => 9]
```

**[compact](https://www.php.net/manual/en/function.compact.php)** Create array containing variables and their values

```
// Add documentation
```

**[count](https://www.php.net/manual/en/function.count.php)** Counts all elements in an array or in a Countable object

```
use Barogue\Collections\Collection;

$collection = new Collection([1, 2, 3]);

count($collection); // 3
$collection->count(); // 3
```

**[current](https://www.php.net/manual/en/function.current.php)** Return the current element in an array

```
// Add documentation
```

**[each](https://www.php.net/manual/en/function.each.php)** Return the current key and value pair from an array and advance the array cursor

```
// Add documentation
```

**[extract](https://www.php.net/manual/en/function.extract.php)** Import variables into the current symbol table from an array

```
// Add documentation
```

**[implode](https://www.php.net/manual/en/function.implode.php)** Join array elements with a string

```
use Barogue\Collections\Collection;
echo Collection::instance('a', 'b', 'c')->implode(', '); // "a, b, c"
echo Collection::instance('a', 'b', 'c')->implode(', ', ' and '); // "a, b and c"
```

**[in\_array](https://www.php.net/manual/en/function.in-array.php)** Checks if a value exists in an array

```
// Add documentation
```

**[krsort](https://www.php.net/manual/en/function.krsort.php)** Sort an array by key in descending order

```
use Barogue\Collections\Collection;

$collection = new Collection(['a' => 5, 'c' => 4, 'z' => 3, 'b' => 2, 'e' => 1]);
$sorted = $collection->sortKeys()->reverse(); // ['z' => 3, 'e' => 1, 'c' => 4, 'b' => 2, 'a' => 5]
```

**[ksort](https://www.php.net/manual/en/function.ksort.php)** Sort an array by key in ascending order

```
use Barogue\Collections\Collection;

$collection = new Collection(['a' => 5, 'c' => 4, 'z' => 3, 'b' => 2, 'e' => 1]);
$sorted = $collection->sortKeys(); // ['a' => 5, 'b' => 2, 'c' => 4, 'e' => 1, 'z' => 3]
```

**[list](https://www.php.net/manual/en/function.list.php)** Assign variables as if they were an array

```
use Barogue\Collections\Collection;

$collection = new Collection(['coffee', 'brown', 'caffeine']);
list($drink, $color, $power) = $collection;
echo $drink; // coffee
echo $color; // brown
echo $power; // caffeine
```

**[natcasesort](https://www.php.net/manual/en/function.natcasesort.php)** Sort an array using a case insensitive "natural order" algorithm

```
// Add documentation
```

**[natsort](https://www.php.net/manual/en/function.natsort.php)** Sort an array using a "natural order" algorithm

```
// Add documentation
```

**[range](https://www.php.net/manual/en/function.range.php)** Create an array containing a range of elements

```
use Barogue\Collections\Collection;

$numbers = Collection::range(0, 100);
$even = Collection::range(0, 100, 2);
$alphabet = Collection::range('a', 'z');
```

**[rsort](https://www.php.net/manual/en/function.rsort.php)** Sort an array in descending order

```
use Barogue\Collections\Collection;

$collection = new Collection(['a' => 9, 'b' => 1, 'c' => 5]);
$collection->reverseSort()->values(); // [9, 5, 1]
```

**[shuffle](https://www.php.net/manual/en/function.shuffle.php)** Shuffle an array

```
use Barogue\Collections\Collection;

$collection = new Collection(['a' => 1, 'b' => 2, 'c' => 3]);
$collection->shuffle(); // ['b' => 2, 'c' => 3, 'a' => 1]
$collection->shuffle(false); // [3, 1, 2]
```

**[sizeof](https://www.php.net/manual/en/function.sizeof.php)** Alias of count

```
use Barogue\Collections\Collection;

$collection = new Collection([1, 2, 3]);

count($collection); // 3
$collection->count(); // 3
```

**[sort](https://www.php.net/manual/en/function.sort.php)** Sort an array in ascending order

```
use Barogue\Collections\Collection;

$collection = new Collection(['a' => 9, 'b' => 5, 'c' => 1]);
$collection->sort()->values(); // [1, 5, 9]
```

**[uasort](https://www.php.net/manual/en/function.uasort.php)** Sort an array with a user-defined comparison function and maintain index association

```
use Barogue\Collections\Collection;

$collection = new Collection([5, 4, 3, 2, 1]);
$collection->sortCallback(function($a, $b) {
    $aEven = $a % 2 == 0 ? 1 : 0;
    $bEven = $b % 2 == 0 ? 1 : 0;
    return $aEven === $bEven ? $a  $b : $aEven  $bEven;
}); // [4 => 1, 2 => 3, 0 => 5, 3 => 2, 1 => 4]
```

**[uksort](https://www.php.net/manual/en/function.uksort.php)** Sort an array by keys using a user-defined comparison function

```
use Barogue\Collections\Collection;

$collection = new Collection([5, 4, 3, 2, 1]);
$collection->sortCallback(function($a, $b) {
    $aEven = $a % 2 == 0 ? 1 : 0;
    $bEven = $b % 2 == 0 ? 1 : 0;
    return $aEven === $bEven ? $a  $b : $aEven  $bEven;
}); // [1 => 4, 3 => 2, 0 => 5, 2 => 3, 4 => 1]
```

**[usort](https://www.php.net/manual/en/function.usort.php)** Sort an array by values using a user-defined comparison function

```
use Barogue\Collections\Collection;

$collection = new Collection([5, 4, 3, 2, 1]);
$collection->sortCallback(function($a, $b) {
    $aEven = $a % 2 == 0 ? 1 : 0;
    $bEven = $b % 2 == 0 ? 1 : 0;
    return $aEven === $bEven ? $a  $b : $aEven  $bEven;
})->values(); // [1, 3, 5, 2, 4]
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

993d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/62f4942978644437b5ff3d7bd3f6411580413d327b001104acd4914f43ab63b6?d=identicon)[kusabi](/maintainers/kusabi)

---

Top Contributors

[![kusabi](https://avatars.githubusercontent.com/u/22000941?v=4)](https://github.com/kusabi "kusabi (8 commits)")

---

Tags

phpcollectioncollectionsarraysbarogue

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/barogue-collection/health.svg)

```
[![Health](https://phpackages.com/badges/barogue-collection/health.svg)](https://phpackages.com/packages/barogue-collection)
```

###  Alternatives

[ilya/belt

A handful of tools for PHP developers.

71020.8k1](/packages/ilya-belt)[cartalyst/collections

Collection Abstaction library for PHP.

76908.6k4](/packages/cartalyst-collections)[rotexsoft/versatile-collections

A collection package that can be extended to implement things such as a Dependency Injection Container, RecordSet objects for housing database records, a bag of http cookies, or technically any collection of items that can be looped over and whose items can each be accessed using array-access syntax or object property syntax.

186.0k1](/packages/rotexsoft-versatile-collections)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
