Sort an array by using a "natural order" algorithm. The values keep their original keys in PHP
Description
The following code shows how to sort an array by using a "natural order" algorithm. The values keep their original keys.
Example
//from w w w.java 2 s. c o m
<?php
$temp_files = array("t15.txt","T10.txt","t1.txt","T22.txt","t2.txt");
natsort($temp_files);
echo "Natural order: ";
print_r($temp_files);
echo "<br />";
natcasesort($temp_files);
echo "Natural order case insensitve: ";
print_r($temp_files);
?>
The code above generates the following result.