Latest web development tutorials

PHP natcasesort () function

PHP Array Reference Complete PHP Array Reference

Definition and Usage

natcasesort () function uses a "natural order" algorithm to sort the array. Keys retain their original keys.

Natural sorting algorithm, the number is smaller than the number 10. In computer sorting algorithms, 10 is less than 2, because the "10" the first number is less than 2.

This function is not case-sensitive.

If successful, the function returns TRUE, on failure returns FALSE.

grammar

natcasesort(array)

参数 描述
array 必需。规定要进行排序的数组。


Examples

<?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
)


PHP Array Reference Complete PHP Array Reference