antikirra/array-sort

1.0.0 2023-05-24 13:24 UTC

This package is auto-updated.

Last update: 2024-09-24 20:21:18 UTC


README

Install

composer require antikirra/array-sort

Basic usage

<?php

require __DIR__ . '/vendor/autoload.php';

// only if the function has not been defined in the global scope
array_sort($array, SORT_DESC, $byKey = true);

// if the function could not be defined globally
\Antikirra\array_sort($array, SORT_DESC, $byKey = true);

// under the hood
\Antikirra\ArraySort\ArraySort::sort($array, SORT_DESC, $byKey = true);

Demo

<?php

require __DIR__ . '/vendor/autoload.php';

$array = ['b' => 3, 'a' => 8, 'c' => 5];

array_sort($array, SORT_DESC, $byKey = true);

// Array
// (
//     [c] => 5
//     [b] => 3
//     [a] => 8
// )

array_sort($array, SORT_ASC, $byKey = false, $preserveKeys = true);

// Array
// (
//     [b] => 3
//     [c] => 5
//     [a] => 8
// )