Current Location: Home> Function Categories> natcasesort

natcasesort

Use the "natural sorting" algorithm to sort the array case-insensitive letters
Name:natcasesort
Category:Array
Programming Language:php
One-line Description:Use the "natural sort" algorithm to sort the arrays insensitively.

Definition and usage

natcasesort() function uses the "natural sort" algorithm to sort the array. Key values ​​retain their original key names.

In 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 case-insensitive.

If successful, the function returns TRUE, and if failed, it returns FALSE.

Example

 <?php
$temp_files = array ( "temp15.txt" , "Temp10.txt" ,
"temp1.txt" , "Temp22.txt" , "temp2.txt" ) ;

natsort ( $temp_files ) ;
echo "Natural sorting:" ;
print_r ( $temp_files ) ;
echo "<br />" ;

natcasesort ( $temp_files ) ;
echo "Case-insensitive natural sorting:" ;
print_r ( $temp_files ) ;
?>

Output of the above code:

 Natural sort:

Array
(
[0] => Temp10.txt
[1] => Temp22.txt
[2] => temp1.txt
[4] => temp2.txt
[3] => temp15.txt
)

Natural order in case insensitive:

Array
(
[2] => temp1.txt
[4] => temp2.txt
[0] => Temp10.txt
[3] => temp15.txt
[1] => Temp22.txt
)

grammar

 natcasesort ( array )
parameter describe
array Required. Specifies the array to be sorted.
Similar Functions
Popular Articles