0

Trying to understand how to sort the following array based on the value. Tried the regular functions for sort, asort, ksort etc like:

sort($array) but no luck. Any thoughts?

   Array
   (
    [0] => Array
        (
            [text] => 2015-01-01 - 2015-12-31
            [value] => 2015-01-01
        )

    [1] => Array
        (
            [text] => 2018-01-01 - 2018-12-31
            [value] => 2018-01-01
        )

    [2] => Array
        (
            [text] => 2017-01-01 - 2017-12-31
            [value] => 2017-01-01
        )

    [3] => Array
        (
            [text] => 2014-01-01 - 2014-12-31
            [value] => 2014-01-01
        )

    [4] => Array
        (
            [text] => 2013-01-01 - 2013-12-31
            [value] => 2013-01-01
        )
    
)
Nick
  • 138,499
  • 22
  • 57
  • 95
Kevin Lindmark
  • 1,155
  • 3
  • 13
  • 26
  • I believe you need to use `usort` with your own comparison function (or maybe `uasort`): https://www.php.net/manual/en/function.usort.php – UnholySheep Sep 10 '20 at 12:11
  • Use `usort` and in your comparator function just use `return strcmp($a['value'], $b['value']);` – Nick Sep 10 '20 at 12:21

0 Answers0