X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

PHP natsort() Function

PHP Array Reference PHP Array Reference

Example

Sort an array:

<?php
$temp_files = array("temp15.txt","temp10.txt",
"temp1.txt","temp22.txt","temp2.txt");

sort($temp_files);
echo "Standard sorting: ";
print_r($temp_files);
echo "<br>";

natsort($temp_files);
echo "Natural order: ";
print_r($temp_files);
?>

Run example »

Definition and Usage

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

In a natural algorithm, the number 2 is less than the number 10. In computer sorting, 10 is less than 2, because the first number in "10" is less than 2.


Syntax

natsort(array)

Parameter Description
array Required. Specifies the array to sort

Technical Details

Return Value: Returns TRUE on success, or FALSE on failure.
PHP Version: 4+
Changelog: As of PHP 5.2.10, Zero padded numeric strings (e.g., '00006') now ignore the 0 padding


PHP Array Reference PHP Array Reference

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook