PHP natcasesort() Function

PHP natcasesort Function


Defintion:

PHP natcasesort is an inbuilt function in PHP. It sorts an array using natural order algorithm in a case-insensitive manner. The sorting is done in a way a normal human will sort the array. Also, it does not check for the type of value for comparison.

For example, in string representation 40 is less than 8 in standard sorting algorithms as 4 comes before 8 lexicographically. However, in natural order 40 is greater than 8. In this article, we will discuss the PHP natcasesort Function.

Syntax

The basic syntax of the natcasesort() function is given with:

   natcasesort(array);

Parameters:

The natcasesort() function accepts the following parameters.

Parameter Description
array Required. Specifies the array to be sorted.

 

Example : Following example shows the natcasesort() function in action.

Output

Array
(
    [0] => IMG2.png
    [1] => IMG5.png
    [2] => img1.png
    [3] => img10.png
)
Array
(
    [2] => img1.png
    [0] => IMG2.png
    [1] => IMG5.png
    [3] => img10.png
)