1// array sort php
2$room_details = array(
3 "2020-09-27": [
4 {
5 "content": "how are you",
6 "detail_id": "1",
7 "time": "17:57:28",
8 "chat_time": "2020-09-24 17:57:28",
9 "width": "0",
10 "height": "0",
11 "type": "1",
12 "distance_time": "26 days ago",
13 "avatar": "uploads/MemberImage/20200922-1436-image-5f699b536f438-0.png",
14 "position": 2
15 },
16 {
17 "content": "I am fine, thanks",
18 "detail_id": "2",
19 "time": "17:57:45",
20 "chat_time": "2020-09-24 17:57:45",
21 "width": "0",
22 "height": "0",
23 "type": "1",
24 "distance_time": "26 days ago",
25 "avatar": "uploads/MemberImage/20200922-1436-image-5f699b536f438-0.png",
26 "position": 2
27 },
28 ],
29 "2020-09-24": [
30 {
31 "content": "how are you",
32 "detail_id": "1",
33 "time": "17:57:28",
34 "chat_time": "2020-09-24 17:57:28",
35 "width": "0",
36 "height": "0",
37 "type": "1",
38 "distance_time": "26 days ago",
39 "avatar": "uploads/MemberImage/20200922-1436-image-5f699b536f438-0.png",
40 "position": 2
41 },
42 {
43 "content": "I am fine, thanks",
44 "detail_id": "2",
45 "time": "17:57:45",
46 "chat_time": "2020-09-24 17:57:45",
47 "width": "0",
48 "height": "0",
49 "type": "1",
50 "distance_time": "26 days ago",
51 "avatar": "uploads/MemberImage/20200922-1436-image-5f699b536f438-0.png",
52 "position": 2
53 },
54 ],
55);
56
57sort($room_details);
58
59// result
60// array sort php
61$room_details = array(
62 "2020-09-24": [
63 ...
64 ],
65 "2020-09-27": [
66 ...
67 ],
68);
69
1function rearrange_array($array, $key) {
2 while ($key > 0) {
3 $temp = array_shift($array);
4 $array[] = $temp;
5 $key--;
6 }
7 return $array;
8}
9