Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. CollectionInterface.php

function CollectionInterface::sort

Sort the collection by a property, method, or array key with the given sort order.

If $propertyOrMethod is `null`, this will sort by comparing each element.

This will always leave the original collection untouched and will return a new one.

Parameters

string | null $propertyOrMethod The property, method, or array key: to sort by.

Sort $order The sort order for the resulting collection.:

Return value

CollectionInterface<T>

Throws

InvalidPropertyOrMethod if the $propertyOrMethod does not exist on the elements in this collection.

UnsupportedOperationException if unable to call sort() on this collection.

1 method overrides CollectionInterface::sort()
AbstractCollection::sort in vendor/ramsey/collection/src/AbstractCollection.php

File

vendor/ramsey/collection/src/CollectionInterface.php, line 139

Class

CollectionInterface
A collection represents a group of values, known as its elements.

Namespace

Ramsey\Collection

Code

public function sort(?string $propertyOrMethod = null, Sort $order = Sort::Ascending) : self;

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal