Example 1: sort array of array php
sort()
rsort()
asort()
ksort()
arsort()
krsort()
$array = array(1, 3, 2);
sort($array)
Example 2: sort array php
<?php
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
asort($fruits);
foreach ($fruits as $key => $val) {
echo "$key = $val\n";
}
?>
//Would output:
c = apple
b = banana
d = lemon
a = orange
Example 3: array sort php
<?php
$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);
foreach ($fruits as $key => $val) {
echo $val;
}
?>
Example 4: php sort()
<?php
$fruits = array("Zitrone", "Orange", "Banane", "Apfel");
sort($fruits);
foreach ($fruits as $key => $val) {
echo "fruits[" . $key . "] = " . $val . "\n";
}
?>
Example 5: php array sort
function cmp($a, $b) {
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
}
Example 6: array sort php
$room_details = array(
"2020-09-27": [
{
"content": "how are you",
"detail_id": "1",
"time": "17:57:28",
"chat_time": "2020-09-24 17:57:28",
"width": "0",
"height": "0",
"type": "1",
"distance_time": "26 days ago",
"avatar": "uploads/MemberImage/20200922-1436-image-5f699b536f438-0.png",
"position": 2
},
{
"content": "I am fine, thanks",
"detail_id": "2",
"time": "17:57:45",
"chat_time": "2020-09-24 17:57:45",
"width": "0",
"height": "0",
"type": "1",
"distance_time": "26 days ago",
"avatar": "uploads/MemberImage/20200922-1436-image-5f699b536f438-0.png",
"position": 2
},
],
"2020-09-24": [
{
"content": "how are you",
"detail_id": "1",
"time": "17:57:28",
"chat_time": "2020-09-24 17:57:28",
"width": "0",
"height": "0",
"type": "1",
"distance_time": "26 days ago",
"avatar": "uploads/MemberImage/20200922-1436-image-5f699b536f438-0.png",
"position": 2
},
{
"content": "I am fine, thanks",
"detail_id": "2",
"time": "17:57:45",
"chat_time": "2020-09-24 17:57:45",
"width": "0",
"height": "0",
"type": "1",
"distance_time": "26 days ago",
"avatar": "uploads/MemberImage/20200922-1436-image-5f699b536f438-0.png",
"position": 2
},
],
);
sort($room_details);
$room_details = array(
"2020-09-24": [
...
],
"2020-09-27": [
...
],
);