我得到下面的代碼語法錯誤:
function getFridays($year='', $format='', $timezone = 'UTC') {
$fridays = array();
$startDate = new DateTime("{$year}-01-01 Friday", new DateTimezone($timezone));
$year++;
$endDate = new DateTime("{$year}-01-01", new DateTimezone($timezone));
$int = new DateInterval('P7D');
foreach (new DatePeriod($startDate, $int, $endDate) as $d) {
$fridays[] = $d->format($format);
}
return $fridays;
}
$fridays = getFridays($year, 'Y-m-d', 'America/New_York');
Error: unexpected '$fridays' (T_VARIABLE), expecting function (T_FUNCTION)
如果在控制器 – user4419336
上,在codeigniter'$ this-> getFridays($ year,'Ym-d','America/New_York')'上添加您的整個班級,因爲如果我將您的代碼複製到沙箱中,罰款,你可以在這裏看到http://sandbox.onlinephpfunctions.com/code/2d7fc79f19389cc9a5a2379ad546230c56bd8a0d – sintakonte