Answer the question
In order to leave comments, you need to log in
How to sort multidimensional associative array by only one value?
Hello.
Here is the array:
$test = [
[
'date' => '1',
'message' => 'Первый'
],
[
'date' => '3',
'message' => '1 Третий'
],
[
'date' => '2',
'message' => 'Второй'
],
[
'date' => '3',
'message' => '0 Четвертый'
],
[
'date' => '0',
'message' => 'Нулевой'
]
];
$test = [
[
'date' => '0',
'message' => 'Нулевой'
],
[
'date' => '1',
'message' => 'Первый'
],
[
'date' => '2',
'message' => 'Второй'
],
[
'date' => '3',
'message' => '1 Третий'
],
[
'date' => '3',
'message' => '0 Четвертый'
]
];
$test = [
[
'date' => '0',
'message' => 'Нулевой'
],
[
'date' => '1',
'message' => 'Первый'
],
[
'date' => '2',
'message' => 'Второй'
],
[
'date' => '3',
'message' => '0 Четвертый'
],
[
'date' => '3',
'message' => '1 Третий'
]
];
function cmp($a, $b) {
$a = $a['date'];
$b = $b['date'];
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
}
uasort($test, 'cmp');
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question