Antonio Papa
Antonio Papa

Reputation: 1666

sorting array: descending arsort returns 1

I have an array and when I run print_r($array) I get:

Array
(
    [XS] => 110
    [S] => 171
    [M] => 172
    [L] => 171
    [XL] => 171
    [2X] => 172
    [3X] => 154
    [4X] => 139
    [5X] => 47
    [6X] => 32
    [OSFA] => 12
    [FITTED S-M] => 12
    [FITTED L-XL] => 12
    [ADJ] => 52
    [YXS] => 15
    [YSM] => 20
    [YMD] => 20
    [YLG] => 20
    [YXL] => 17
    [TLG] => 1
    [TXL] => 1
    [T2X] => 1
    [T3X] => 3
    [S-M FLEX] => 3
    [M-L FLEX] => 3
    [L-XL FLEX] => 3
    [CHILD STRETCH] => 1
    [S/M] => 1
 )

I want to sort it descending, but arsort returns 1. I can sort it with for loop but I want the best solution. Any suggestion?

Upvotes: 1

Views: 1714

Answers (1)

rohitarora
rohitarora

Reputation: 1365

use arsort($icon,SORT_NUMERIC); you can sort the data as numeric put ur data on $icon

Upvotes: 2

Related Questions