0

I have to sort the given array on date key in PHP. I have tried it using array_multisort but not able to sort it. which one is more appropriate usort or array_multisort?

Array
(
    [165953] => Array
        (
            [0] => Array
                (
                    [wallet_transaction_id] => 165953
                    [wallet_currency_id] => 2
                    [description] => updating SC Dollars by 100.00 from PSM product transaction.
                    [amount] => 100.00
                    [date] => 2013-11-13 08:08:05
                )

            [1] => Array
                (
                    [wallet_transaction_id] => 165953
                    [wallet_currency_id] => 3
                    [description] => updating Spy Points by 50.00 from PSM product transaction.
                    [amount] => 50.00
                    [date] => 2013-11-13 06:08:05
                )

        )

    [165952] => Array
        (
            [0] => Array
                (
                    [wallet_transaction_id] => 165952
                    [wallet_currency_id] => 2
                    [description] => updating SC Dollars by 100.00 from PSM product transaction.
                    [amount] => 100.00
                    [date] => 2013-11-13 05:02:11
                )

            [1] => Array
                (
                    [wallet_transaction_id] => 165952
                    [wallet_currency_id] => 3
                    [description] => updating Spy Points by 50.00 from PSM product transaction.
                    [amount] => 50.00
                    [date] => 2013-11-13 08:02:11
                )

        )
)
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
shiv
  • 9
  • 3
  • What do you want the result to look like? I assume for each element in the array (`165953` and `165952`), you want to sort that array... is that right? – gen_Eric Nov 15 '13 at 16:28
  • It is a duplicate. The first answer there works best memory-wise, and speed-wise. – Alex Nov 15 '13 at 16:31

1 Answers1

0

You should look the usort function. It let's you define your own comparison function.

http://www.php.net/manual/en/function.usort.php

William Vbl
  • 503
  • 3
  • 8