\TriTanListUtil

List Utility

Summary

Methods
Properties
Constants
__construct()
getInput()
getOutput()
filter()
pluck()
sort()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
sortCallback()
$input
$output
$orderby
N/A

Properties

$input

$input : array

The input array.

Type

array

$output

$output : array

The output array.

Type

array

$orderby

$orderby : array

Temporary arguments for sorting.

Type

array

Methods

__construct()

__construct(array  $input) 

Constructor.

Sets the input array.

Parameters

array $input

Array to perform operations on.

getInput()

getInput() : array

Returns the original input array.

Returns

array —

The input array.

getOutput()

getOutput() : array

Returns the output array.

Returns

array —

The output array.

filter()

filter(array  $args = array(), string  $operator = 'AND') : array

Filters the list, based on a set of key => value arguments.

Parameters

array $args

Optional. An array of key => value arguments to match against each object. Default empty array.

string $operator

Optional. The logical operation to perform. 'AND' means all elements from the array must match. 'OR' means only one element needs to match. 'NOT' means no elements may match. Default 'AND'.

Returns

array —

Array of found values.

pluck()

pluck(integer|string  $field, integer|string  $index_key = null) : array

Plucks a certain field out of each object in the list.

This has the same functionality and prototype of array_column() (PHP 5.5) but also supports objects.

Parameters

integer|string $field

Field from the object to place instead of the entire object

integer|string $index_key

Optional. Field from the object to use as keys for the new array. Default null.

Returns

array —

Array of found values. If $index_key is set, an array of found values with keys corresponding to $index_key. If $index_key is null, array keys from the original $list will be preserved in the results.

sort()

sort(string|array  $orderby = array(), string  $order = 'ASC', boolean  $preserve_keys = false) : array

Sorts the list, based on one or more orderby arguments.

Parameters

string|array $orderby

Optional. Either the field name to order by or an array of multiple orderby fields as $orderby => $order.

string $order

Optional. Either 'ASC' or 'DESC'. Only used if $orderby is a string.

boolean $preserve_keys

Optional. Whether to preserve keys. Default false.

Returns

array —

The sorted array.

sortCallback()

sortCallback(object|array  $a, object|array  $b) : integer

Callback to sort the list by specific fields.

Parameters

object|array $a

One object to compare.

object|array $b

The other object to compare.

Returns

integer —

0 if both objects equal. -1 if second object should come first, 1 otherwise.