Skip to content

Kirby 5.1.2

$assets->sort()

Sorts the elements by any number of fields

$assets->sort(string|callable $field, string|null $direction, int|null $method): Kirby\Plugin\Assets

Parameters

Name Type Default Description
$fieldrequired stringorcallable no default value Field name or value callback to sort by
$direction stringornull no default value asc or desc
$method intornull no default value The sort flag, SORT_REGULAR, SORT_NUMERIC etc.

Return types

Kirby\Plugin\Assets

This method does not modify the existing $assets object but returns a new object with the changes applied. Learn more →

Parent class

Kirby\Plugin\Assets inherited from Kirby\Toolkit\Collection

Examples

$collection->sort('fieldName');
$collection->sort('fieldName', 'desc');
$collection->sort('fieldName', 'asc', SORT_REGULAR);
$collection->sort(fn ($a) => ...);