Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP natcasesort() Function

PHP natcasesort() Function


PHP Array ReferenceComplete PHP Array Reference Manual


Definition and Usage

The natcasesort() function sorts an array using a "natural ordering" algorithm. The values keep their original keys.

In natural ordering, the number 2 is less than the number 10. In computer sorting, 10 is less than 2 because the first digit in "10" is less than 2.

This function is case-insensitive.

Returns TRUE on success, FALSE on failure.

Syntax

natcasesort(array)

Parameters Description
array Required. Specifies the array to sort.

Example

"; natcasesort($temp_files); echo "Natural order case insensitve: "; print_r($temp_files); ?>

The code above 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 ReferenceComplete PHP Array Reference Manual