Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

natcasesort()

Arrange case-insensitive names in natural order, treating unpadded digit runs as numbers while preserving keys.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

natcasesort(array &$array): true

Arrange case-insensitive names in natural order, treating unpadded digit runs as numbers while preserving keys. Names that differ only by case retain their input order in PHP 8. The sort modifies the array and returns true. The numeric rule applies to ordinary unpadded digit runs. With leading zeros f010 precedes f02. Ignoring ASCII case does not normalize Unicode.

Signature

natcasesort(array &$array): true

Example output

[true,["b","c","a"],["log2","LOG2","Log10"]]
["f010","f02"]

Examples

<?php
$files = ["a"=>"Log10","b"=>"log2","c"=>"LOG2"];
$ok = natcasesort($files);
echo json_encode([$ok,array_keys($files),array_values($files)]);
$padded=["f02","f010"]; natcasesort($padded); echo PHP_EOL,json_encode(array_values($padded));

Result

[true,["b","c","a"],["log2","LOG2","Log10"]]
["f010","f02"]

Sources