Computer >> Computer tutorials >  >> Programming >> PHP

natcasesort() function in PHP


The natcasesort() sorts an array using a case insensitive "natural order" algorithm.

Note − This function is case-insensitive.

Syntax

natcasesort(arr)

Parameters

  • arr − The array to sort

Return

The natcasesort() function returns TRUE on success, or FALSE on failure.

Example

The following is an example −

<?php
$stu_rank = array("Rank10","Rank2","rank3","rank1","Rank7","rank4");
natcasesort($stu_rank);
print_r($stu_rank);
?>

Output

The following is the output that shows case insensitive sort −

Array (
   [3] => rank1
   [1] => Rank2
   [2] => rank3
   [5] => rank4
   [4] => Rank7
   [0] => Rank10
)