I have an array of strings corresponding to names of images in a directory.
Here is an example:
array(3) { [0]=> string(5) "3.png" [1]=> string(5) "2.jpg" [2]=> string(6) "4.jpeg" }
How could I reorder that array so that the numbers before the extensions increases such as the example below:
array(3) { [0]=> string(5) "2.jpg" [1]=> string(5) "3.png" [2]=> string(6) "4.jpeg" }
use sort
function:
$array = array(
'2.png',
'4.png',
'1.png',
);
sort($array);
print_r($array);
Output:
Array ( [0] => 1.png [1] => 2.png [2] => 4.png )
For more detail have a look at: PHP Array Sorting
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments