method sort documentation in bbn\X

Sorts the items of an array.

Example

$var = [3, 2, 5, 6, 1]; X::sort($var); X::hdump($var); // array [1,2,3,5,6] function(array &$ar, bool $backward = false) { usort( $ar, function ($a, $b) use ($backward) { if (!Str::isNumber($a, $b)) { $a = str_replace('.', '0', str_replace('_', '1', Str::changeCase($a, 'lower'))); $b = str_replace('.', '0', str_replace('_', '1', Str::changeCase($b, 'lower'))); return $backward ? strcmp($b, $a) : strcmp($a, $b); } if ($a > $b) { return $backward ? -1 : 1; } elseif ($a == $b) { return 0; } return $backward ? 1 : -1; } ); }

Sorts the items of an array. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.