PHPackages                             dimaskao/sorter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dimaskao/sorter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dimaskao/sorter
===============

This library can sort array.

v2.0.1(5y ago)04BSD-3-ClausePHPPHP &gt;=7.4

Since Aug 22Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Dimaskao/Sorter)[ Packagist](https://packagist.org/packages/dimaskao/sorter)[ RSS](/packages/dimaskao-sorter/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

Library for sorting
===================

[](#library-for-sorting)

This library can sort array with numbers and letters.

Table of contents
=================

[](#table-of-contents)

- [Installation](#Installation)
- [How to use](#How-to-use)
    - [General](#General)
    - [NullSorter](#NullSorter)
- [Library extension](#Library-extension)
- [Example](#Example)

Installation
------------

[](#installation)

You can use composer to install this extension.

Just run:

```
$ composer require dimaskao/sorter

```

How to use
----------

[](#how-to-use)

### General

[](#general)

At first include this library classes:

```
require_once __DIR__ . '/XXXXX/vendor/autoload.php';

use Dimaskao\Sorter\Sorter //required class

use Dimaskao\Sorter\NullSorter; //|\
use Dimaskao\Sorter\SortASC;    //|- Choose what you need
use Dimaskao\Sorter\SortDESC;   //|/
```

Where `XXXXX` path to library root folder.

If you want to sort array create `Sorter` object and pass `SortASC` or `SortDESC` object.

```
$sorter = new Sorter(new SortASC());
```

Then use `->sort()` method and pass an array to it. This method will return a sorted array.

```
$sorter->sort($array);
```

This library use Strategy patterns so you can cheng sorting method by `-setSorter()`. Just pass it a new sort object.

```
$sorter = new Sorter(new SortDESC());

$sorter->setSorter(new SortASC());
```

### NullSorter

[](#nullsorter)

For debugging you can use `NullSorter()`.

```
$sorter->setSorter(new SortASC());//this will sort array
$sorter->setSorter(new NullSorter());//this would not sort array
$b = $sorter->sort($arr);
```

Library extension
-----------------

[](#library-extension)

If you would add new formats of sorting, you should create your own class which implements `SorterInterface.php`.

```
require_once __DIR__ . '/vendor/autoload.php';

use Dimaskao\Sorter\SorterInterface;

class YourFormat implements SorterInterface {

}
```

Example
-------

[](#example)

Let's see how it works.

```
require_once __DIR__ . 'vendor/autoload.php';

use Dimaskao\Sorter\NullSorter;
use Dimaskao\Sorter\SortASC;
use Dimaskao\Sorter\SortDESC;
use Dimaskao\Sorter\Sorter;

$arr = [9, 0, 1, 5, 77, -5];

$sorter = new Sorter(new SortDESC());
$a = $sorter->sort($arr);

\print_r($a);

$sorter->setSorter(new SortASC());
$b = $sorter->sort($arr);

\print_r($b);

$sorter->setSorter(new SortASC());
$sorter->setSorter(new NullSorter());
$b = $sorter->sort($arr);

\print_r($b);
```

As a result, we get.

```
Array
(
    [4] => 77
    [0] => 9
    [3] => 5
    [2] => 1
    [1] => 0
    [5] => -5
)
Array
(
    [5] => -5
    [1] => 0
    [2] => 1
    [3] => 5
    [0] => 9
    [4] => 77
)
Array
(
    [0] => 9
    [1] => 0
    [2] => 1
    [3] => 5
    [4] => 77
    [5] => -5
)
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

2093d ago

Major Versions

v1.0.1 → v2.0.02020-08-23

### Community

Maintainers

![](https://www.gravatar.com/avatar/30b8f039bba7550ba7ef642afeeb6b9c73757527a03074209051410b13254501?d=identicon)[Dimaskao](/maintainers/Dimaskao)

---

Top Contributors

[![Dimaskao](https://avatars.githubusercontent.com/u/59502015?v=4)](https://github.com/Dimaskao "Dimaskao (15 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/dimaskao-sorter/health.svg)

```
[![Health](https://phpackages.com/badges/dimaskao-sorter/health.svg)](https://phpackages.com/packages/dimaskao-sorter)
```

###  Alternatives

[2tvenom/cborencode

CBOR encoder for PHP

6213.1M17](/packages/2tvenom-cborencode)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
