class SortArray (View source)

Provides generic array sorting helper methods.

Methods

static int
sortByWeightElement(array $a, array $b)

Sorts a structured array by the 'weight' element.

static int
sortByWeightProperty(array $a, array $b)

Sorts a structured array by '#weight' property.

static int
sortByTitleElement(array $a, array $b)

Sorts a structured array by 'title' key (no # prefix).

static int
sortByTitleProperty(array $a, array $b)

Sorts a structured array by '#title' property.

static int
sortByKeyString(array $a, array $b, string $key)

Sorts a string array item by an arbitrary key.

static int
sortByKeyInt(array $a, array $b, string $key)

Sorts an integer array item by an arbitrary key.

Details

static int sortByWeightElement(array $a, array $b)

Sorts a structured array by the 'weight' element.

Note that the sorting is by the 'weight' array element, not by the render element property '#weight'.

Callback for uasort().

Parameters

array $a

First item for comparison. The compared items should be associative arrays that optionally include a 'weight' element. For items without a 'weight' element, a default value of 0 will be used.

array $b

Second item for comparison.

Return Value

int

The comparison result for uasort().

static int sortByWeightProperty(array $a, array $b)

Sorts a structured array by '#weight' property.

Callback for uasort().

Parameters

array $a

First item for comparison. The compared items should be associative arrays that optionally include a '#weight' key.

array $b

Second item for comparison.

Return Value

int

The comparison result for uasort().

static int sortByTitleElement(array $a, array $b)

Sorts a structured array by 'title' key (no # prefix).

Callback for uasort().

Parameters

array $a

First item for comparison. The compared items should be associative arrays that optionally include a 'title' key.

array $b

Second item for comparison.

Return Value

int

The comparison result for uasort().

static int sortByTitleProperty(array $a, array $b)

Sorts a structured array by '#title' property.

Callback for uasort().

Parameters

array $a

First item for comparison. The compared items should be associative arrays that optionally include a '#title' key.

array $b

Second item for comparison.

Return Value

int

The comparison result for uasort().

static int sortByKeyString(array $a, array $b, string $key)

Sorts a string array item by an arbitrary key.

Parameters

array $a

First item for comparison.

array $b

Second item for comparison.

string $key

The key to use in the comparison.

Return Value

int

The comparison result for uasort().

static int sortByKeyInt(array $a, array $b, string $key)

Sorts an integer array item by an arbitrary key.

Parameters

array $a

First item for comparison.

array $b

Second item for comparison.

string $key

The key to use in the comparison.

Return Value

int

The comparison result for uasort().