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
- Second day of the week
- Third day of the week
- Fourth day of the week
- Fifth day of the week
- Sixth day of the week
- Seventh day of the week
Week 15 - First day of the week
- Second day of the week
- Third day of the week
- Fourth day of the week
- Fifth day of the week
- Sixth day of the week
- Seventh day of the week
Week 16 - First day of the week
- Second day of the week
- Third day of the week
- Fourth day of the week
- Fifth day of the week
- Sixth day of the week
- 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
精彩评论