我想将php变量top
包含到具有参数
$i
在上面的代码中我想将函数名称设为for($i=1; $i<=50; $i++) {
$currentMonth = date("F");
/* draws a calendar */
function draw_calendar($month,$year,$per_day_chu){
$currentDayOfMonth = date("j");
/* draw table */
$calendar = '<table cellpadding="0" cellspacing="0" class="calendar">';
/* table headings */
$headings = array('Su','Mo','Tu','Wed','Th','Fr','Sa');
$calendar.= '<tr class="calendar-row"><td class="calendar-day-head">'.implode('</td><td class="calendar-day-head">',$headings).'</td></tr>';
/* days and weeks vars now ... */
$running_day = date('w',mktime(0,0,0,$month,1,$year));
$days_in_month = date('t',mktime(0,0,0,$month,1,$year));
$days_in_this_week = 1;
$day_counter = 0;
$dates_array = array();
/* row for week one */
$calendar.= '<tr class="calendar-row">';
return $calendar;
}
echo $currentMonth.", ".date("Y");
echo draw_calendar(date("m"), date("Y"), $per_day_chu);
}
,函数调用为function draw_calendar$i($month,$year,$per_day_chu){
有没有办法实现这一目标。我不知道如何设置它。三江源。
答案 0 :(得分:3)
你应该将你的函数放在循环之外,然后将调用放入循环中。
答案 1 :(得分:2)
我认为你实际上需要这样做: -
for($i=1; $i<=50; $i++) {
$currentMonth = date("F");
echo $currentMonth.", ".date("Y");
echo draw_calendar(date("m"), date("Y"), $per_day_chu);
}
function draw_calendar($month,$year,$per_day_chu){
$currentDayOfMonth = date("j");
$calendar = '<table cellpadding="0" cellspacing="0" class="calendar">';
$headings = array('Su','Mo','Tu','Wed','Th','Fr','Sa');
$calendar.= '<tr class="calendar-row"><td class="calendar-day-head">'.implode('</td><td class="calendar-day-head">',$headings).'</td></tr>';
$running_day = date('w',mktime(0,0,0,$month,1,$year));
$days_in_month = date('t',mktime(0,0,0,$month,1,$year));
$days_in_this_week = 1;
$day_counter = 0;
$dates_array = array();
$calendar.= '<tr class="calendar-row">';
return $calendar;
}
注意: -
内部循环中的函数代码是错误的做法。同时检查$per_day_chu
圈内每次for
是否可用,并且每次都有正确的值。