The natcasesort() function sorts an array using the "natural sorting" algorithm. Key values retain their original key names.
In the natural sorting algorithm, the number 2 is less than the number 10. In computer sorting algorithms, 10 is less than 2 because the first number in "10" is less than 2.
This function is not case sensitive.
The function returns TRUE if successful and FALSE if failed.
natcasesort(array)
parameter | describe |
---|---|
array | Required. Specifies the array to be sorted. |
<?php$temp_files = array("temp15.txt","Temp10.txt","temp1.txt","Temp22.txt","temp2.txt");natsort($temp_files);echo "Natural order: ";print_r($temp_files);echo "<br />";natcasesort($temp_files);echo "Natural order case insensitve: ";print_r($temp_files);?>
The above code will output:
Natural order:Array([0] => Temp10.txt[1] => Temp22.txt[2] => temp1.txt[4] => temp2.txt[3] => temp15.txt)Natural order case insensitve :Array([2] => temp1.txt[4] => temp2.txt[0] => Temp10.txt[3] => temp15.txt[1] => Temp22.txt)