numberedStringOrder
Sort an array of strings based on the included numbers naturally. An alternative to PHP built-in natsort function that's actually work.
Install
Via Composer
$ composer require awssat/numbered-string-orderUsage
Sort
//if you are using laravel, then instead use:
//$numberedStringOrder = app(Awssat\numberedStringOrder\numberedStringOrder::class);
$numberedStringOrder = new numberedStringOrder();
$numberedStringOrder->sort([
'episode 5',
'episode50',
'499',
'episode1',
'episode two hundred',
'episode one',
'episode two',
'episode eleven',
'episode three'
]);
>> output:
[
"episode1",
"episode one",
"episode two",
"episode three",
"episode 5",
"episode eleven",
"episode50",
"episode two hundred",
499,
]
If you ask why not use the built-in function (natsort), then see the natsort output of the same example above to know why:
//output of built-in function natsor(): π€¨
[
"499",
"episode1",
"episode 5",
"episode50",
"episode eleven",
"episode one",
"episode three",
"episode two",
"episode two hundred",
]Get the numbers
If you want to use our internal numbers extracting method
$numberedStringOrder->getNumbers(['2digits', 'text1', 'three3', 'two cars', 'blank']);
>> output:
[
"2digits" => 2,
"text1" => "1",
"three3" => "3",
"two cars" => 2,
"blank" => "blank",
]Convert words to numbers
This package can also be helpful if you want to convert numerical words to numbers
new numberedStringOrder();
$numberedStringOrder->englishWordsToNumbers('one hundred twenty-three thousand four hundred fifty-six');
>> output: 123456
//to get arabic words to number use: arabicWordsToNumbers(...)Test
composer testCurrently, it supports English and Arabic.
License
The MIT License (MIT). Please see License File for more information.

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
