natcasesort()

natcasesort() — Sort an array using a case insensitive "natural order" algorithm.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

Signature

natcasesort(array &$array): true

Parameters

ParameterTypeWhat it takes
&$arrayarrayThe input array.

Return value

Always returns true.

Example

A runnable snippet:

$array1 = $array2 = array('IMG0.png', 'img12.png', 'img10.png', 'img2.png', 'img1.png', 'IMG3.png'); 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] => IMG0.png [1] => IMG3.png [2] => img1.png [3] => img10.png [4] => img12.png [5] => img2.png ) Natural order sorting (case-insensitive) Array ( [0] => IMG0.png [4] => img1.png [3] => img2.png [5] => IMG3.png [2] => img10.png [1] => img12.png )

Changelog

VersionChange
8.2.0The return type is true now; previously, it was bool.

See also

natsort(), strnatcmp(), strnatcasecmp()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page natcasesort() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.