I have the following output values from a associative array (id => value):
1GB - 4GB
1TB - 2TB
3TB - 5TB
5GB - 16GB
6TB+
17GB - 32GB
33GB - 63GB
64GB - 120GB
121GB - 200GB
201GB - 300GB
301GB - 500GB
501GB - 1TB
How can I group and sort it so that I get it goes from smallest to largest:
so:
1GB - 4GB
5GB - 16GB
17GB - 32GB
33GB - 63GB
64GB - 120GB
121GB - 200GB
201GB - 300GB
301GB - 500GB
501GB - 1TB
1TB - 2TB
3TB - 5TB
6TB+
Posting my comment as an answer for posterity...
When you have strings that cannot be easily sorted and you are fetching the data from a database table, you can:
Add a column called weight
to the table that is of data type
integer
In the weight column use higher or lower numbers depending on how you want the data sorted.
When querying the data add ORDER BY weight DESC
to your query to
fetch the results in the way you want it