开发者

PHP array of days, sort by week

Hi I have an array of days from day X to day Y witch var_dumps this:

array(7) {

 ["week"]=> string(2) "14"
 ["year"]=> string(4) "2011"
 ["month"]=> string(2) "04"
 ["day"]=> string(2) "09"
 ["sunrise"]=> string(5) "06:32"
 ["sunset"]=> string(5) "20:09"
 ["daylength"]=> string(5) "13:37"
} 

Now what I want to do is to sort the list of days wich are returned into an accordion with the weeks devided into an list 开发者_C百科that looks somthing like this

Week 14 - First day of the week

  1. Second day of the week
  2. Third day of the week
  3. Fourth day of the week
  4. Fifth day of the week
  5. Sixth day of the week
  6. Seventh day of the week

Week 15 - First day of the week

  1. Second day of the week
  2. Third day of the week
  3. Fourth day of the week
  4. Fifth day of the week
  5. Sixth day of the week
  6. Seventh day of the week

Week 16 - First day of the week

  1. Second day of the week
  2. Third day of the week
  3. Fourth day of the week
  4. Fifth day of the week
  5. Sixth day of the week
  6. Seventh day of the week

And so on...

All help is appreciated. Thank you so much


you probably want to use usort

function dateSort($a, $b) {
  if($a['year'] != $b['year'])
    return $a['year'] - $b['year'];
  return ($a['week'] == $b['week'])
    ? $a['day'] - $b['day']
    : $a['week'] - $b['week'];
}

usort($array, "dateSort");

this should sort your array by year, then week and then day

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜