Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP natsort() Function

PHP natsort() Function

PHP Array ReferenceComplete PHP Array Reference Manual

Example

Sort an array:

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

Run Example »


Definition and Usage

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

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


Syntax

natsort(

array

)

Parameters Description
array Required. Specifies the array to sort.

Technical Details

Return Value: Returns TRUE on success, FALSE on failure.
PHP Version: 4+
Changelog: Since PHP 5.2.10, zero-padded numeric strings (such as '00006') ignore the leading zeros.

PHP Array ReferenceComplete PHP Array Reference Manual