10c05-3.php

来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 42 行

PHP
42
字号
<?php// Create a function that will return an option list of months:function month_options() {	$retval = '';		// For all twelve months:	foreach(range(1,12) as $mon) {		// Make a timestamp for this month:		$time = mktime(0, 0, 0, $mon);		// Use date to return the month name as text:		$name = date('F', $time);		// Create the select option:		$retval .= "<option value=\"{$mon}\">{$name}</option>\n";	}		return $retval;}// Create a function, that will output a list of years// The first parameter is how many years in the past to start from// The second parameter is how many years into the future to go:function year_options($before, $after) {	$retval = '';		// From the current year:	$cyear = date('Y');	// Loop over the range requested:	foreach(range($cyear - $before, $cyear + $after) as $y) {		// Store the select option:		$retval .= "<option value=\"{$y}\">{$y}</option>\n";	}		return $retval;}// Now we can just output a simple form using these:?><form><p>Month:<select name="month"><?= month_options() ?></select></p><p>Year:<select name="year"><?= year_options(5, 10) ?></select></p></form>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?