Array sort function in PHP

前端 未结 3 975
一向
一向 2020-12-22 12:04

I defined a myArr = (\"Apr\",\"Mar\",\"May\"). Is there a sorting function to sort the array members by nature month sequence otherwise by alphabet.

Th

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-22 12:17

    You could use usort() and create your own function to compare months.

    function monthCompare($a, $b)
    {
      $months = array('jan' => 1, 'feb' => 2..._);
      if($a == $b)
      {
        return 0;
      }
      return ($months[$a] > $months[$b]) ? 1 : -1;
    }
    

提交回复
热议问题