|
|
Tutorials » Php »
|
Topic |
What is natsort() Function?
|
|
Explanation |
|
The "natsort()" function sorts an array using a "natural order" algorithm.
Syntax:
natsort(array)
In the above syntax "array" is the array to be sorted using the natural order algorithm.
Example
<?php
$psd_files = array("psd15.psd","psd10.psd",
"psd1.psd","psd22.psd","psd2.psd");
natsort($psd_files);
echo "Natural order: ";
print_r($psd_files);
Result:
Array
Natural Order
{
[2]= psd1.psd
[4]= psd2.psd
[0]= Psd10.psd
[3]= psd15.psd
[1]= Psd22.psd
}
In the above example from the array "$psd_files",elements are sorted using the natural algorithm, not based on the keys.
|
|
A Note |
Learn PHP programming language tutorial with simple and neat example. Hope you enjoy this free tutorial.
Do give us your valuable feedback and suggestions on this online tutorial. This is a Copyright Content.
|
|
|
|