PHP natcasesort() Function

Definition

The natcasesort() function sorts an array by using a "natural order" algorithm. The values keep their original keys.

Syntax

PHP natcasesort() Function has the following syntax.

natcasesort(array)

Parameter

ParameterIs RequiredDescription
arrayRequired.Array to sort

Return

This function returns TRUE on success, or FALSE on failure.

Note

This function is case-insensitive.

Example 1

Sorts an array by using a "natural order" algorithm.


<?php/*w  w  w .jav a2s .c  o m*/
$temp_files = array("A1","A11","A12","B","B0","java2s.com");

natsort($temp_files);
echo "Natural order: ";
print_r($temp_files);
echo "<br />";

natcasesort($temp_files);
echo "Natural order case insensitve: ";
print_r($temp_files);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions