class Sort extends ArrayMutator (View source)

Sorts an array. The callback is used to retrieve the value to sort by. If no callback is provided, the value itself is used.

Preserves key association by default. To reset key association, set $preserveKeys to false.

Supports built-in PHP sorting flags. See https://www.php.net/manual/en/function.sort.php for more information.

Methods

__construct(SortDirection $direction = SortDirection::Asc, callable $callback = null, bool $preserveKeys = true, int $flags = SORT_REGULAR)

No description

mixed
__invoke(mixed $value)

Mutate the input value.

from  Mutator
static Sort
asc(callable $callback = null, bool $preserveKeys = true, int $flags = SORT_REGULAR)

Sorts an array in ascending order.

static Sort
desc(callable $callback = null, bool $preserveKeys = true, int $flags = SORT_REGULAR)

Sorts an array in descending order.

static Sort
make(SortDirection $direction = SortDirection::Asc, callable $callback = null, bool $preserveKeys = true, int $flags = SORT_REGULAR)

No description

mixed
mutate(mixed $value)

Mutate the input value.

array
mutateArray(array $array)

No description

Details

__construct(SortDirection $direction = SortDirection::Asc, callable $callback = null, bool $preserveKeys = true, int $flags = SORT_REGULAR)

No description

Parameters

SortDirection $direction

The direction to sort by (optional, default: SortDirection::Asc)

callable $callback

The callback to retrieve the value to sort by (optional)

bool $preserveKeys

Whether to preserve key association (default: true)

int $flags

Flags to pass to the PHP sort function (default: SORT_REGULAR)

final mixed __invoke(mixed $value)

Mutate the input value.

Parameters

mixed $value

Return Value

mixed

static Sort asc(callable $callback = null, bool $preserveKeys = true, int $flags = SORT_REGULAR)

Sorts an array in ascending order.

Parameters

callable $callback

The callback to retrieve the value to sort by (optional)

bool $preserveKeys

Whether to preserve key association (default: true)

int $flags

Flags to pass to the PHP sort function (default: SORT_REGULAR)

Return Value

Sort

static Sort desc(callable $callback = null, bool $preserveKeys = true, int $flags = SORT_REGULAR)

Sorts an array in descending order.

Parameters

callable $callback

The callback to retrieve the value to sort by (optional)

bool $preserveKeys

Whether to preserve key association (default: true)

int $flags

Flags to pass to the PHP sort function (default: SORT_REGULAR)

Return Value

Sort

static Sort make(SortDirection $direction = SortDirection::Asc, callable $callback = null, bool $preserveKeys = true, int $flags = SORT_REGULAR)

No description

Parameters

SortDirection $direction

The direction to sort by (optional, default: SortDirection::Asc)

callable $callback

The callback to retrieve the value to sort by (optional)

bool $preserveKeys

Whether to preserve key association (default: true)

int $flags

Flags to pass to the PHP sort function (default: SORT_REGULAR)

Return Value

Sort

mixed mutate(mixed $value)

Mutate the input value.

Parameters

mixed $value

Return Value

mixed

protected array mutateArray(array $array)

No description

Parameters

array $array

Return Value

array