php The natcasesort() function is used to sort the array with the "natural sorting" algorithm, and the key values retain their original key names. The syntax is natcasesort(array), and the parameter array is required and refers to the array to be sorted.
##php How to use the natcasesort function?
php natcasesort() function syntax
Function: Sort the array using the "natural sorting" algorithm. Key values retain their original key names.
Syntax:
natcasesort(array)
Parameters:
array Required. Specifies the array to be sorted.
Explanation:
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.
php natcasesort() function example
<?php $arr = array("string1","string10","string01","string2","string20","string02"); natcasesort($arr); print_r($arr); ?>
Output:
Array ( [2] => string01 [5] => string02 [0] => string1 [3] => string2 [1] => string10 [4] => string20 )
This article is an introduction to the PHP natcasesort function. I hope it will be helpful to friends who need it. Helps!
The above is the detailed content of How to use php natcasesort function. For more information, please follow other related articles on the PHP Chinese website!