我试图获取数组的结果并将其移至$variable
。
这是我目前的代码:
<?php
$total_days_month = date('t'); // total days this month
// add "$currentday" day number to an array until $currentday<=$total_days_month
$days_array = array();
for ($currentday=1; $currentday<=$total_days_month; $currentday++) {
if ($total_days_month > $currentday)
{
array_push($days_array,"'$currentday',");
}
else
{
array_push($days_array,"'$currentday'");
}
}
// now transfer the array content to a $variable
$variable = ????
?>
$variable
内容必须为'1', '2', '3', '4' ........ '31'
答案 0 :(得分:3)
$variable = implode("','", $days_array);
答案 1 :(得分:2)
<?php
$total_days_month = date('t'); // total days this month
// add "$currentday" day number to an array until $currentday<=$total_days_month
$days_array = array();
for ($currentday=1; $currentday<=$total_days_month; $currentday++) {
if ($total_days_month > $currentday){
array_push($days_array,"'$currentday',");
}else{
array_push($days_array,"'$currentday',");
}
}
// now transfer the array content to a $variable
$variable = implode(',', $days_array);