Helper class for working with arrays.

package Default

 Methods

Asserts that an array does not contain duplicates regarding a member.

assertNoDuplicates(array $_array, callable $key) : array
Static

Throws \FeaturePhp\Helper\ArrayException if duplicates are found.

Parameters

$_array

array

$key

callable

Returns

array

Finds an array element by comparing a member with the given value.

findByKey(array $array, callable $key, mixed $value) : object
Static

Parameters

$array

array

$key

callable

$value

mixed

Returns

object

Sorts an array regarding a custom key using the decorate-sort-undecorate pattern.

schwartzianTransform(array $_array, callable $func) : array
Static

This is useful if the key should only be calculated once per element (https://gregheo.com/blog/schwartzian-transform/).

Parameters

$_array

array

$func

callable

extracts a string value from an element

Returns

array

Sorts an array in ascending order regarding a member.

sortByKey(array $_array, callable $key) : array
Static

Parameters

$_array

array

$key

callable

Returns

array