src/Collection/ArrayCollection.php
public function sortBy(callable $callback, $options = SORT_REGULAR, $descending = false): ArrayCollection
    {
        $items = [];

        foreach ($this->items as $key => $value) {
            $items[$key] = $callback($value, $key);
        }

        if ($descending) {
            arsort($items, $options);
        } else {
            asort($items, $options);
        }

        foreach (array_keys($items) as $key) {
            $items[$key] = $this->items[$key];
        }

        return new static($items);
    }
public function sortBy(callable $callback, $options = SORT_REGULAR, $descending = false): ArrayCollection
    {
        $items = [];

        foreach ($this->items as $key => $value) {
            $items[$key] = $callback($value, $key);
        }

        if ($descending) {
            arsort($items, $options);
        } else {
            asort($items, $options);
        }

        foreach (array_keys($items) as $key) {
            $items[$key] = $this->items[$key];
        }

        return new static($items);
    }
public function sortBy ( callable $ callback , $ options = SORT_REGULAR , $ descending = false ) : ArrayCollection { $ items = [ ] ; foreach ( $ this -> items as $ key => $ value ) { $ items [ $ key ] = $ callback ( $ value , $ key ) ; } if ( $ descending ) { arsort ( $ items , $ options ) ; } else { asort ( $ items , $ options ) ; } foreach ( array_keys ( $ items ) as $ key ) { $ items [ $ key ] = $ this -> items [ $ key ] ; } return new static ( $ items ) ; }
Creates a sorted collection using values from a callback

Callback function should return a value for comparison

Callback signature:

<code>
function ($value, $key): mixed {}
</code>

@param callable $callback   The callback function
@param int      $options    The sort options
@param bool     $descending Whether to sort in descending order

@return ArrayCollection
Creates a sorted collection using values from a callback