0

我有一个假期清单,例如:

var holiDays =[[2013,01,01,'New Years Day'],[2013-05-27, 'Memorial Day']]

并在 celender 上显示,但这个列表是硬编码的,所以我想要一个 php 中的函数,以便所有假期列表可见。 $(function() { $("#id_holiday_date").datepicker({ beforeShowDay: setHoliDays });

      // set holidays function which is configured in beforeShowDay
     function setHoliDays(date) {
       for (i = 0; i < holiDays.length; i++) {
         if (date.getFullYear() == holiDays[i][0]
              && date.getMonth() == holiDays[i][1] - 1
              && date.getDate() == holiDays[i][2]) {
            return [true, 'holiday', holiDays[i][3]];
         }
       }
      return [true, ''];
    }

 });


this function work properly in date picker.this date picker takes date from hardcoded array.
I want a function like that:
function calculateHolidays($year = '') {

$holiDays = Array();
$year = ($year != '') ? $year : date('Y'); //Default Current Year
$newYear = "$year-01-01";
$temp = "$year-05-00 last monday";
$memorialDay = strtotime($temp);//last Monday of May for Current Year

提前致谢

4

2 回答 2

1

如果我是你,我会看看梨约会假期。

于 2013-03-01T11:08:26.220 回答
0

这是一种方法 - 如果您想找到[]给定年份的所有括号:

function display_holidays($year,$list){
    echo "<ul>";
    $list=str_replace(array('[[',']]','],['),array('[',']',']|['),$list);
    $list=explode("|",$list);
    foreach($list as $item){
        // find the items with the correct year
        if(strstr($item,"[".$year)){
            echo "<li>".$item."</li>";
        }
    }
    echo "</ul>";
}

使用示例:

$list="[[2012,01,01,'New Years Day'],[2013,05,27, 'Memorial Day']]";
$year=2013;
display_holidays($year,$list);

结果将是:

<ul>
   <li>[2013,05,27, 'Memorial Day']</li>
</ul>

ps:但请更详细地解释您想要实现的目标。

于 2013-03-01T11:27:49.437 回答