人人商城函数之get_last_day()获取当月最后一天

函数名称

函数位置

ewei_shopv2/core/inc/functions.php

函数源码

if (!function_exists('get_last_day')) {
	function get_last_day($year, $month)
	{
		return date('t', strtotime($year . '-' . $month . ' -1'));
	}
}

拓展

可循环获取指定月份的最后一天。

//读取当前月份最大日期 28/30/31
$days = get_last_day(date('Y'), date('m'));

//Yangjunwei:读取当月所有日期 S
$d = 1;
while ($d <= $days) {
	$yjw_months[] = strlen($d) == 1 ? '0' . $d : $d;
	++$d;
}
print_r($yjw_months);
//Yangjunwei:读取当月所有日期 E

上述代码打印示例

Array(
	[0] => 01
	[1] => 02
	[2] => 03
	[3] => 04
	[4] => 05
	[5] => 06
	[6] => 07
	[7] => 08
	[8] => 09
	[9] => 10
	[10] => 11
	[11] => 12
	[12] => 13
	[13] => 14
	[14] => 15
	[15] => 16
	[16] => 17
	[17] => 18
	[18] => 19
	[19] => 20
	[20] => 21
	[21] => 22
	[22] => 23
	[23] => 24
	[24] => 25
	[25] => 26
	[26] => 27
	[27] => 28
	[28] => 29
	[29] => 30
	[30] => 31
)