PHP natsort() Function

Definition

The natsort() function sorts an array by using a "natural order" algorithm.

Syntax

PHP natsort() Function has the following syntax.

natsort(array)

Parameter

ParameterIs RequiredDescription
arrayRequired.Specifies the array to sort

Note

This function is case-sensitive.

Return

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

Example 1

Sort an array:


<?php/*  w  w w. ja  va 2  s .c o m*/
$temp_files = array("a15","A10","A1","A22","A2");

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

natsort($temp_files);
echo "Natural order: ";
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