PHP natcasesort array function

Last Updated: February 21, 2022

natcasesort – Sort an array using a case insensitive “natural order” algorithm

Syntax

natcasesort(array &$array): bool

Supports (PHP 4 , PHP 5, PHP 7, PHP 8)

Parameters

Parameter Description
array input array

Return Value

Always return true

Example

$array1 = $array2 = array('a', 'c', 'b', 'D', 'E', 'F');

sort($array1);
echo "Standard sorting\n";
print_r($array1);

natcasesort($array2);
echo "\nNatural order sorting (case-insensitive)\n";
print_r($array2);

Output

Standard sorting Array ( [0] => D [1] => E [2] => F [3] => a [4] => b [5] => c )

Natural order sorting (case-insensitive) Array ( [0] => a [2] => b [1] => c [3] => D [4] => E [5] => F )

Test