CoolCMS API

ArrayHelper
in package

Table of Contents

Methods

reindex()  : array<string|int, mixed>
Reindexes an array of objects; the key becomes the return value of the given method.
sortByCallback()  : array<string|int, object>
Sorts an array of objects with a custom comparison callback.
sortByMethod()  : array<string|int, object>
Sorts an array of objects ascending by the return value of the given method.
sortByMethodDesc()  : array<string|int, object>
Sorts an array of objects descending by the return value of the given method.
validateMethod()  : void
Checks that the method exists on the first element of the array.

Methods

reindex()

Reindexes an array of objects; the key becomes the return value of the given method.

public static reindex(array<string|int, object> $objects, string $method) : array<string|int, mixed>
Parameters
$objects : array<string|int, object>
$method : string

Method returning the new key (e.g. 'getId', 'getSlug')

Return values
array<string|int, mixed>

sortByCallback()

Sorts an array of objects with a custom comparison callback.

public static sortByCallback(array<string|int, object> $objects, callable(object, object): int $comparator) : array<string|int, object>
Parameters
$objects : array<string|int, object>
$comparator : callable(object, object): int
Return values
array<string|int, object>

sortByMethod()

Sorts an array of objects ascending by the return value of the given method.

public static sortByMethod(array<string|int, object> $objects, string $method) : array<string|int, object>
Parameters
$objects : array<string|int, object>
$method : string

Method returning the sort key (e.g. 'getId', 'getName')

Return values
array<string|int, object>

sortByMethodDesc()

Sorts an array of objects descending by the return value of the given method.

public static sortByMethodDesc(array<string|int, object> $objects, string $method) : array<string|int, object>
Parameters
$objects : array<string|int, object>
$method : string
Return values
array<string|int, object>

validateMethod()

Checks that the method exists on the first element of the array.

private static validateMethod(array<string|int, mixed> $objects, string $method) : void
Parameters
$objects : array<string|int, mixed>
$method : string
On this page

Search results