【发布时间】:2011-03-25 03:12:01
【问题描述】:
我是一个 PHP 新手,但我正在尝试通过 for 循环将值(本周的日期)分配给 smarty 数组。不幸的是,经过一个小时的搜索,我无法弄清楚如何解决这个问题。
我能做的最好的事情是将这些日期值分配给七个单独的变量(而不是一个包含七个值的数组)。我的代码如下。谁能帮助我将这些值加载到数组而不是单个变量中?提前感谢您的帮助。
global $smarty;
// Set current date and parse about any English textual datetime description into a Unix timestamp
$ts = strtotime('now');
// Calculate the number of days since Monday
$dow = date('w', $ts);
$offset = $dow - 1;
if ($offset < 0) $offset = 6;
// Calculate timestamp for the Monday
$ts = $ts - $offset*86400;
// This is where I want to assign dates to a smarty array, not individual variables
for ($i=0; $i<7; $i++, $ts+=86400){
$smarty->assign('day'.$i,date("m/d/Y l", $ts));
}
【问题讨论】:
标签: php arrays variables loops smarty