English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The natsort() function sorts an array using the 'Natural Sorting' algorithm
natsort ( $array );
This function implements a sorting algorithm that sorts alphanumeric strings in a way similar to humans, while keeping the keys/Value Association. This is called 'Natural Sorting'.
Serial Number | Parameters and Description |
---|---|
1 | array(Required) It specifies an array |
This function returns TRUE on success and FALSE on failure.
<?php $input1 = array('click.txt', 'img12.txt', 'img10.txt', 'img2.txt', 'img1.txt', 'IMG3.txt'); $input2 = $input1; natsort($input2); echo " \n Natural Sorting \n"; print_r($input2); ?>Test and See‹/›
Output Result:
Natural Sorting Array ( [0] => click.txt [5] => IMG3.txt [4] => img1.txt [3] => img2.txt [2] => img10.txt [1] => img12.txt )