如何定义日是星期日和正常日。 按日期使用开关盒? [关闭]

I have an error in this code. Please help me solve it.

function holiday($today) {    

    $year = substr($today, 0, 4);     

    switch($today) {

      case $year.'-01-01':
          $holiday = 'New Year';
          break;

      case $today:
          $today11 = new DateTime($today);
          $R= $today11->format('l') . PHP_EOL;
          $Sunday='0';

          if($R == 0) {
              $holiday = 'Sunday';
          } else {
              $holiday = 'Normal Day';  
          }
      }

      return $holiday;
}

echo $tday= holiday($today); 

Try it:-

function holyday($today)
{
    $start_date = strtotime($today);


    if(date('z',$start_date) ==0)
    {
         return 'New Year';

    }else{

        if(date('l',$start_date) =='Sunday')
        {
             return 'Sunday';

        }else{

            return "Noraml Day";
        }
    }
}

echo holyday('2012-09-06');

Output = Noraml Day

echo holyday('2013-01-01');

Output = New year

Not sure why you're using switch for this, please read up on how to use switch. The function below will work:

function holiday($today) {
    // z returns the number of the day in the year, 0 being first of January
    if(date("z", $today) == 0) {
         return "New Year";
    }

    // w returns the number of the day in the week 0-6 where 0 is Sunday
    if(date("w", $today) == 0) {
         return "Sunday";
    }

    return "Normal Day";
}

$today = date();
echo holiday($today);

Here is a working implementation of your holiday() function:

function holiday($today) {    

$date = strtotime($today);     

//check if Sunday
if (date('l', $date) == 'Sunday') {
    return 'Sunday';
}

//check if New Year
if ((date('j', $date) == 1) && (date('n', $date) == 1)) {
    return 'New Year';
}

//else, just return Normal Day
return 'Normal Day';

}

//$today is in YYY/MM/DD format
echo $tday = holiday($today);

Also, PHP's date reference can come in handy in this case: http://php.net/manual/en/function.date.php