0

I have an array like this. I need to sort countries (array key) by [0][amount] value.

Array
(
    [Germany] => Array
        (
            [0] => Array
                (
                    [amount] => 50
                    [count] => 1
                )

        )

    [Poland] => Array
        (

            [0] => Array
                (
                    [amount] => 80
                    [count] => 2
                )

        )

)

Result should be Poland first and Germany. Any idea in PHP?

JEROME
  • 139
  • 1
  • 8
  • 2
    possible duplicate of [How to sort an array of associative arrays by value of a given key in PHP?](http://stackoverflow.com/questions/1597736/how-to-sort-an-array-of-associative-arrays-by-value-of-a-given-key-in-php) – Derek Aug 04 '15 at 14:25
  • uasort and then array_keys – splash58 Aug 04 '15 at 14:25

1 Answers1

0

I got it..

$amount = array();
foreach ($originArray as $key => $value)
{
        $amount[$key] = $value[0]['amount'];
}
array_multisort($amount, SORT_DESC, $originArray);
JEROME
  • 139
  • 1
  • 8