Answer the question
In order to leave comments, you need to log in
How to sort PHP multidimensional array with complex conditions?
Hello everyone
Given a PHP array, it contains 5 others
array(5) {
[4]=>
array(3) {
["autor_id"]=>
int(4)
["count_msg"]=>
int(5)
["last_date"]=>
int(1606350743)
}
[2]=>
array(3) {
["autor_id"]=>
int(2)
["count_msg"]=>
int(7)
["last_date"]=>
int(1606350737)
}
[6]=>
array(3) {
["autor_id"]=>
int(6)
["count_msg"]=>
int(29)
["last_date"]=>
int(1606350733)
}
[1]=>
array(4) {
["autor_id"]=>
int(1)
["count_msg"]=>
int(36)
["last_date"]=>
int(1606350726)
["unread_pm"]=>
int(1)
}
[3]=>
array(3) {
["autor_id"]=>
int(3)
["count_msg"]=>
int(8)
["last_date"]=>
int(1606349427)
}
}
Answer the question
In order to leave comments, you need to log in
array_multisort(
array_column($array, 'unread_pm'), SORT_DESC,
array_column($array, 'last_date'), SORT_DESC,
$array
);
SELECT ... ORDER BY unread_pm DESC, last_date DESC
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question