PHP 8 reference · Array Sorting Functions
PHP natcasesort() Function
Sort an array in natural order while ignoring case, keeping keys. "Item2" comes before "item10".
PHP 8 Since 4.0
Syntax
natcasesort(array &$array): true
Parameters
| Parameter | Description |
|---|---|
array |
The array to sort (changed in place). |
Return value
Always true.
Examples
<?php
$names = ["Item10", "item2", "ITEM1"];
natcasesort($names);
echo implode(", ", $names), "\n";
Output
ITEM1, item2, Item10
<?php
$list = ["b2", "A10", "a2"];
natsort($list);
echo implode(", ", $list), "\n";
natcasesort($list);
echo implode(", ", $list), "\n";
Output
A10, a2, b2 a2, A10, b2
Version history
Related
natsort()· Sort an array in natural order, so "img2" comes before "img10", keeping keys. Case-sensitive.strnatcasecmp()· Compare strings in natural order ("a2" before "a10") while ignoring upper and lower case.- PHP Arrays · tutorial
- PHP Array Functions · tutorial