Skip to content

Commit e5ab057

Browse files
committed
Don't keep index association when sorting, this yields arrays like [1 => 'second', 0 => 'first']
These arrays are not zero-based and considered maps e.g. by typeof() or the string representation creation functions
1 parent 100ff20 commit e5ab057

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ Data sequences change log
33

44
## ?.?.? / ????-??-??
55

6+
* Don't keep index association when sorting, this yields arrays like
7+
`[1 => 'second', 0 => 'first']`. These arrays are not zero-based and
8+
considered maps e.g. by typeof()
9+
(@thekid)
10+
611
## 2.1.0 / 2015-01-18
712

813
* Heads up: Removed `sum()` operation, it can easily be rewritten to

src/main/php/util/data/Sequence.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,13 +510,13 @@ public function distinct() {
510510
public function sorted($comparator= null) {
511511
$sort= $this->toArray();
512512
if ($comparator instanceof Comparator) {
513-
uasort($sort, Functions::$COMPARATOR->newInstance([$comparator, 'compare']));
513+
usort($sort, Functions::$COMPARATOR->newInstance([$comparator, 'compare']));
514514
} else if (is_int($comparator)) {
515515
array_multisort($sort, $comparator);
516516
} else if ($comparator) {
517-
uasort($sort, Functions::$COMPARATOR->newInstance($comparator));
517+
usort($sort, Functions::$COMPARATOR->newInstance($comparator));
518518
} else {
519-
asort($sort);
519+
sort($sort);
520520
}
521521
return new self($sort);
522522
}

0 commit comments

Comments
 (0)