fix months order
This commit is contained in:
parent
3e6f00c387
commit
35d6587379
2 changed files with 22 additions and 6 deletions
|
|
@ -1,22 +1,36 @@
|
|||
<?php
|
||||
|
||||
function sortByMonth($sessions) {
|
||||
$months = array(
|
||||
$currentMonth = date('F');
|
||||
$frenchMonths = array(
|
||||
'janvier', 'février', 'mars', 'avril', 'mai', 'juin',
|
||||
'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'
|
||||
);
|
||||
$englishMonths = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
|
||||
|
||||
$currentMonthIndex = date('n');
|
||||
|
||||
|
||||
$frenchMonths = array_merge(
|
||||
array_slice($frenchMonths, $currentMonthIndex - 1, 12),
|
||||
array_slice($frenchMonths, 0, $currentMonthIndex - 1)
|
||||
);
|
||||
$englishMonths = array_merge(
|
||||
array_slice($englishMonths, $currentMonthIndex - 1, 12),
|
||||
array_slice($englishMonths, 0, $currentMonthIndex - 1)
|
||||
);
|
||||
|
||||
$orderedSessions = array();
|
||||
|
||||
foreach ($months as $month) {
|
||||
foreach ($frenchMonths as $month) {
|
||||
$orderedSessions[$month] = array();
|
||||
}
|
||||
|
||||
foreach ($sessions as $item) {
|
||||
$month = date('F', strtotime($item['date']));
|
||||
$month = str_replace(
|
||||
array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'),
|
||||
$months,
|
||||
$englishMonths,
|
||||
$frenchMonths,
|
||||
$month
|
||||
);
|
||||
$orderedSessions[$month][] = $item;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue