\Kaloa\UtilArrayObject

Adds grouping and multi-dimensional sorting functions to ArrayObject

See: http://www.ermshaus.org/2010/03/php-kaloa-spl-arrayobject

Please note: This class isn't the most efficient way to perform the implemented operations. A more low-level approach to grouping will be considerably faster and use less resources, sorting operations should be done in the DMBS (if applicable).

Summary

Methods
Properties
Constants
__construct()
groupBy()
usort()
usortm()
uasortm()
uksortm()
getArrayCopyRec()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

__construct()

__construct(array  $array) 

Adds possibility to pass multi-dimensional arrays to the constructor

All arrays found among the values of the passed array will be transformed recursively to instances of ArrayObject.

Parameters

array $array

Data array to initialize class with

groupBy()

groupBy(callback  $func) : \Kaloa\Util\ArrayObject

Groups the array by one or more criteria defined via callback function

Each element in the first dimension of the array is passed to the specified callback function and will be reordered in regard to the returned value. This can either be a string with the new key or an array with a stack of new keys. For an element $e, the callback return value array('a', 'b') translates to $newArray['a']['b'][] = $e;.

Callback functions may take the element argument by reference and modify it during execution (e. g. to remove any fields that will be grouped by).

Parameters

callback $func

Function to group by

Returns

\Kaloa\Util\ArrayObject

Provides fluent interface

usort()

usort(callback  $cmp_function) : boolean

Adds usort as an instance method

Parameters

callback $cmp_function

Function to sort by

Returns

boolean

usortm()

usortm(array|callback  $funcs) : \Kaloa\Util\ArrayObject

Parameters

array|callback $funcs

Returns

\Kaloa\Util\ArrayObject

Provides fluent interface

uasortm()

uasortm(array|callback  $funcs) : \Kaloa\Util\ArrayObject

Parameters

array|callback $funcs

Returns

\Kaloa\Util\ArrayObject

Provides fluent interface

uksortm()

uksortm(array|callback  $funcs) : \Kaloa\Util\ArrayObject

Parameters

array|callback $funcs

Returns

\Kaloa\Util\ArrayObject

Provides fluent interface

getArrayCopyRec()

getArrayCopyRec() : array

Returns the multi-dimensional array structure with all instances of ArrayObject transformed to standard PHP arrays

Returns

array —

Flattened array