diff options
Diffstat (limited to 'src/Iterator/Query.php')
-rw-r--r-- | src/Iterator/Query.php | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/Iterator/Query.php b/src/Iterator/Query.php index e2f1a0a..22544b0 100644 --- a/src/Iterator/Query.php +++ b/src/Iterator/Query.php @@ -177,19 +177,19 @@ trait Query if (! $this->iterator_sort_by) { return $iterator; } + $nb_callbacks = count($this->iterator_sort_by); + $this->iterator_sort_by = array_values($this->iterator_sort_by); $res = iterator_to_array($iterator, false); - - uasort($res, function ($rowA, $rowB) { - foreach ($this->iterator_sort_by as $callable) { - $res = $callable($rowA, $rowB); - if (0 !== $res) { - return $res; - } + uasort($res, function ($rowA, $rowB) use ($nb_callbacks) { + $res = 0; + $index = 0; + while ($index < $nb_callbacks && 0 === $res) { + $res = $this->iterator_sort_by[$index]($rowA, $rowB); + ++$index; } - return 0; + return $res; }); - $this->clearSortBy(); return new ArrayIterator($res); |