public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self
    {
        $array = $this->getArray();
        $direction = $this->getDirection($direction);

        // Transform all values into their results.
        if ($sorter) {
            $arrayy = static::create(
                $array,
                $this->iteratorClass,
                false
            );

            $results = $arrayy->each(
                function ($value) use ($sorter) {
                    if (\is_callable($sorter)) {
                        return $sorter($value);
                    }

                    return $this->get($sorter, null, $this->getArray());
                }
            );

            $results = $results->getArray();
        } else {
            $results = $array;
        }

        // Sort by the results and replace by original values
        \array_multisort($results, $direction, $strategy, $array);

        return static::create(
            $array,
            $this->iteratorClass,
            false
        );
    }
public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self
    {
        $array = $this->getArray();
        $direction = $this->getDirection($direction);

        // Transform all values into their results.
        if ($sorter) {
            $arrayy = static::create(
                $array,
                $this->iteratorClass,
                false
            );

            $results = $arrayy->each(
                function ($value) use ($sorter) {
                    if (\is_callable($sorter)) {
                        return $sorter($value);
                    }

                    return $this->get($sorter, null, $this->getArray());
                }
            );

            $results = $results->getArray();
        } else {
            $results = $array;
        }

        // Sort by the results and replace by original values
        \array_multisort($results, $direction, $strategy, $array);

        return static::create(
            $array,
            $this->iteratorClass,
            false
        );
    }
public function sorter ( $ sorter = null , $ direction = \ SORT_ASC , int $ strategy = \ SORT_REGULAR ) : self { $ array = $ this -> getArray ( ) ; $ direction = $ this -> getDirection ( $ direction ) ; // Transform all values into their results. if ( $ sorter ) { $ arrayy = static :: create ( $ array , $ this -> iteratorClass , false ) ; $ results = $ arrayy -> each ( function ( $ value ) use ( $ sorter ) { if ( \ is_callable ( $ sorter ) ) { return $ sorter ( $ value ) ; } return $ this -> get ( $ sorter , null , $ this -> getArray ( ) ) ; } ) ; $ results = $ results -> getArray ( ) ; } else { $ results = $ array ; } // Sort by the results and replace by original values \ array_multisort ( $ results , $ direction , $ strategy , $ array ) ; return static :: create ( $ array , $ this -> iteratorClass , false ) ; }
Sort a array by value, by a closure or by a property.

- If the sorter is null, the array is sorted naturally.
- Associative (string) keys will be maintained, but numeric keys will be re-indexed.

@param callable|string|null $sorter
@param int|string           $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p>
@param int                  $strategy  <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or
<strong>SORT_NATURAL</strong></p>

@return static
<p>(Immutable)</p>
Sort a array by value by a closure or by a property .