<?php class demo { #编写函数,传入年月日三个值,返回一年当中的第几天 public function getDay($year, $month, $day) { $sum = 0; $rYear = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];//闰年 $Year = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];#平年 if ($year % 4 == 0 && $year % 100 != 0 || $year % 100 == 0) { for ($i = 0; $i < $month - 1; $i++) { $sum += $rYear[$i]; } echo $sum + $day; } else { for ($i = 0; $i < $month - 1; $i++) { $sum += $Year[$i]; } echo $sum + $day; } } } $cs = new demo(); $cs->getDay(2019, 3, 1);