I have an array like this:
[
['array-5', 0],
['array-4', 0],
['array-1',-1],
['array-3', 2],
['array-2', 3]
]
I want to sort this in PHP so that negative numbers are ordered before positive numbers, and if the sign is the same, the magnitude (more negative or more positive) has precedence.
For the example above, the desired output would be:
[
['array-1',-1],
['array-2', 3],
['array-3', 2],
['array-4', 0],
['array-5', 0]
]
If
$datahas your input, you can callusortlike this:After this has executed,
$datawill have the desired order.