Skip to content

IEnumerable.orderDescending() method

Marcel Kloubert edited this page Apr 3, 2021 · 3 revisions

IEnumerable->orderDescending([$algo]) method

Sorts the sequence in decending order by using the elements as sort values.

Syntax

public IEnumerable orderDescending([callable $algo]);

Parameters

Name Type Description
$algo callable [OPTIONAL] The custom sort algorithm.

Result

The ordered sequence.

Examples

Simple example

$seq = Enumerable::values(2, 3, 1);

// [3, 2, 1]
$a = $seq->orderDescending()
         ->toArray();

Custom algorithm

$seq = Enumerable::values('2', '3', '1');

// ['1', '2', '3']
$a = $seq->orderDescending(function($x, $y) { return strcmp($x, $y) * -1; })
         ->toArray();
Clone this wiki locally