PHP Array natcasesort() Function
What is natcasesort() Function?
How to sort an array elements in Natural Order?
Explanation
The "natcasesort()" function sort an array using a case in sensitive "natural order" algorithm. But the keys remain the same.
Syntax:
natcasesort(array)
In the above syntax "array" is the array to be sorted and is case-insensitive.
Example :
<?php
$psd_files = array("psd15.psd","Psd10.psd",
"psd1.psd","Psd22.psd","psd2.psd");
natsort($psd_files);
echo "Natural order: ";
print_r($psd_files);
echo "<br />";
natcasesort($psd_files);
echo "Natural order case insensitve: ";
print_r($psd_files);
?>
Result :
Natural order:
Array
{
[0]= Psd10.psd
[1]= Psd22.psd
[2]= psd1.psd
[4]= psd2.psd
[3]= psd15.psd
}
Natural order case insensitve:
Array
{
[2]= psd1.psd
[4]= psd2.psd
[0]= Psd10.psd
[3]= psd15.psd
[1]= Psd22.psd
}
In the above example the first the array "$psd_files" is displayed using the case sensitive order, then displayed using the case insensitive "natcasesort()" function.