/
sort.php
78 lines (65 loc) · 1.56 KB
/
sort.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
$array = array(
array(
'Cat_ID' => 81751,
'Cat_Name' => 'Äá»i sống',
'Cat_ParentID' => 104,
'Description' => ""
),
array(
'Cat_ID' => 1424,
'Cat_Name' => 'Giải trÃ',
'Cat_ParentID' => 104,
'Description' => ""
),
array(
'Cat_ID' => 1451,
'Cat_Name' => 'Giáo dục',
'Cat_ParentID' => 104,
'Description' => ""
),
array(
'Cat_ID' => 80923,
'Cat_Name' => 'Kh - cn',
'Cat_ParentID' => 104,
'Description' => ""
),
array(
'Cat_ID' => 1426,
'Cat_Name' => 'Kh - cn',
'Cat_ParentID' => 104,
'Description' => ""
),
array(
'Cat_ID' => 1433,
'Cat_Name' => 'Kh - cn',
'Cat_ParentID' => 104,
'Description' => ""
),
array(
'Cat_ID' => 1442,
'Cat_Name' => 'Nhà đất',
'Cat_ParentID' => 104,
'Description' => ""
),
array(
'Cat_ID' => 80891,
'Cat_Name' => 'Ô tô - xe máy',
'Cat_ParentID' => 104,
'Description' => ""
),
array(
'Cat_ID' => -999,
'Cat_Name' => 'Topnews',
'Cat_ParentID' => 0,
'Description' => ""
),
);
function orderBy($data, $field){
$code = "return strnatcmp(\$a['$field'], \$b['$field']);";
usort($data, create_function('$a,$b', $code));
return $data;
}
$sorted_data = orderBy($array, 'Cat_ParentID');
echo "<pre>";
var_dump($sorted_data);