Class of stable sort methods. Equal values remain in the original order. Only different values are sorted.

2.0.5 2020-05-11 08:25 UTC

This package is auto-updated.

Last update: 2020-06-11 08:40:47 UTC


Version 2.0.4 Build Status

Copyright © 2015-2018 Martijn van der Lee ( MIT Open Source license applies.


Class of stable sort utility methods and standalone functions. Equal values remain in the original order. Only different values are sorted.

These sort utility methods follow the same interface and have the same functionality and features as the builtin sort utility methods (except they add guaranteed sort order).

Static methods

  • bool StableSort::arsort ( array &$array [, int $sort_flags = SORT_REGULAR ] )
  • bool StableSort::asort ( array &$array [, int $sort_flags = SORT_REGULAR ] )
  • bool StableSort::natcasesort ( array &Sarray )
  • bool StableSort::natsort ( array &Sarray )
  • bool StableSort::uasort ( array &$array , callable $value_compare_func )
  • bool StableSort::uksort ( array &$array , callable $value_compare_func )
  • bool StableSort::usort ( array &$array , callable $value_compare_func )

For backwards compatibility, functions (prefixed with s) are available that utilize the utility class.


PHPUnitTest testcases are included (group stablesort) in the tests directory.


Only methods that make sense for stable sorting are included, so no sort or ksort variants. If you can demonstrate the case for any missing function, please let me know and they will be included.

These are not the fastest possible implementations. In fact, I guarantee they are not. Performance has been sacrificed for compatibility with their builtin counterparts.



  • Merge @joelpittet 2.0.0 into main branch, cleaning Drupal specifics.


  • Converted to Utility class. By @joelpittet


  • Added reset calls to sasort/sarsort to ensure pointer. By @emilv.


  • PHP 5.3 compatibility changes by @folliked.


  • composer.json added by @thebeline.


  • Initial public release