natsort php

Solutions on MaxInterview for natsort php by the best coders in the world

showing results for - "natsort php"
Enrico
25 Oct 2020
1// create a example array
2$array_1 = array(
3    'pic10.jpg', 'pic3.jpg', 'pic1.jpg', 
4    'pic7.jpg', 'pic99.jpg', 'pic127.jpg'
5);
6 
7// copy array 1
8$array_2 = $array_1;
9 
10 
11sort($array_1);
12 
13print "Standard sorting algorithm:<br/>\n";
14print_r($array_1);
15print "\n\n";
16 
17 
18natsort($array_2);
19 
20print "Natural order sorting:<br/>\n";
21print_r($array_2);
22 
23/*
24Output:
25 
26Standard sorting algorithm
27Array
28(
29    [0] => pic1.jpg
30    [1] => pic10.jpg
31    [2] => pic127.jpg
32    [3] => pic3.jpg
33    [4] => pic7.jpg
34    [5] => pic99.jpg
35)
36 
37 
38Natural order sorting
39Array
40(
41    [2] => pic1.jpg
42    [1] => pic3.jpg
43    [3] => pic7.jpg
44    [0] => pic10.jpg
45    [4] => pic99.jpg
46    [5] => pic127.jpg
47)
48*/
queries leading to this page
natsort in phpnatsort php