Skip to content

Stable sort variants of builtin PHP sort functions. These maintain original order if comparison values are equal.

Notifications You must be signed in to change notification settings

folliked/PHP-stable-sort-functions

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP stable sort functions

Version 1.0.1 Build Status

Copyright © 2015 Martijn van der Lee (http://martijn.vanderlee.com). MIT Open Source license applies.

Introduction

Collection of sort functions using stable sort. Equal values remain in the original order. Only different values are sorted.

These sort functions follow the same interface and have the same functionality and features as the builtin sort functions (except they add guaranteed sort order). They have an "s" prefixed to the function name.

Each function has it's own file. Since you're likely to want to only include the specific function(s) you need, this makes it easier. Just copy & paste.

Functions

  • bool sarsort ( array &$array [, int $sort_flags = SORT_REGULAR ] )
  • bool sasort ( array &$array [, int $sort_flags = SORT_REGULAR ] )
  • bool snatcasesort ( array &Sarray )
  • bool snatsort ( array &Sarray )
  • bool suasort ( array &$array , callable $value_compare_func )
  • bool suksort ( array &$array , callable $value_compare_func )
  • bool susort ( array &$array , callable $value_compare_func )

Tests

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

Disclaimers

Only functions that make sense 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.

Changes

1.0.1

  • composer.json added by @thebeline.

1.0

  • Initial public release

About

Stable sort variants of builtin PHP sort functions. These maintain original order if comparison values are equal.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%