How it is possible to sort an array with decimal values, positive and negative?
With regular sorting it will become like:
9.45
87.00
68.33
10.36
-40.00
-33.23
-3.98
-29.00
any ideas? thanks!
How it is possible to sort an array with decimal values, positive and negative?
With regular sorting it will become like:
9.45
87.00
68.33
10.36
-40.00
-33.23
-3.98
-29.00
any ideas? thanks!
What does "regular sorting" mean? Which function did you use?
Never mind. What bradgrafelman said.
If you want something like this:
array
0 => float 87
1 => float 68.34
2 => float 68.33
3 => float 10.36
4 => float 9.45
5 => float -3.98
6 => float -29
7 => float -33.23
8 => float -40
...that's using rsort(). And the elements in the array were, as you can see, numeric type, not strings.
If using sort() or related commands, you can force a numeric sort via the optional 2nd parameter, even if the values are strings:
rsort($myArray, SORT_NUMERIC);