/** * Implements {@link Pipeable::sort}. * @param callable|null $compareFunction * @return PipeableLike */ public function sort(callable $compareFunction = null) { if ($compareFunction === null) { $compareFunction = Comparators::naturalComparator(); } $array = $this->toArray(); $success = uasort($array, $compareFunction); if ($success === false) { throw new \RuntimeException("sort failed"); } return $this->newCollection($array); }
public function sortProvider() { return [[[1, 2, 4, 3], [1, 2, 3 => 3, 2 => 4]], [[1, 2, 4, 3], [1, 2, 3 => 3, 2 => 4], Comparators::naturalComparator()]]; }