1<?php
2$fruit = array("apple","banana","mango","orange","strawbary");
3
4sort($fruit); //arrange in ascending order
5echo "<pre>";
6print_r($fruit);
7
8rsort( $fruit); //sort in descending order
9foreach($fruit as $val)
10{
11 echo $val."<br>";
12}
13
14$girl = array("krisha"=>20,"yashvi"=>30,"ritu"=>4,"pinal"=>80);
15asort($girl); //sort in ascending order according to value
16print_r($girl);
17
18ksort($girl); //sort in ascending order according to key
19print_r($girl);
20
21arsort($girl); //sort in descending order according to value
22print_r($girl);
23
24krsort($girl); //sort in descending order according to key
25print_r($girl);
26?>
1$price = array();
2foreach ($inventory as $key => $row)
3{
4 $price[$key] = $row['price'];
5}
6array_multisort($price, SORT_DESC, $inventory);
1
2<?php
3$fruits = array("lemon", "orange", "banana", "apple");
4rsort($fruits);
5foreach ($fruits as $key => $val) {
6 echo "$key = $val\n";
7}
8?>
9
10
1<?php
2$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
3asort($fruits);
4foreach ($fruits as $key => $val) {
5 echo "$key = $val\n";
6}
7?>
8//Would output:
9c = apple
10b = banana
11d = lemon
12a = orange
1
2<?php
3
4$fruits = array("lemon", "orange", "banana", "apple");
5sort($fruits);
6foreach ($fruits as $key => $val) {
7 echo $val;
8}
9/*
10OUTPUT:
11apple
12banana
13lemon
14orange
15*/
16?>
17
18
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