Answer the question
In order to leave comments, you need to log in
usort() function. How to do multiple sorting?
I need to sort the array:
1. First, there are numbers that are divisible by 2 without a remainder (these numbers are also in ascending order).
2. Then all the other numbers come in ascending order.
So far it's been like this:
$arr = [1, 4, 3, 2, 5];
usort(
$arr,
fn($a, $b) => $a % 2 === 0 ? -1 : 1
);
// [4, 2, 5, 3, 1]
// А нужно чтобы было так: [2, 4, 1, 3, 5]
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