我有:
for ($i=0; $i < 10; $i++) {
$date = Date('Y-m-d', strtotime("-$i days"));
$numar = $this->Misc->get($date);
// here a want to add to a array $date and $number
}
在阵列上使用foreach循环时我想得到:
Date : X Number : Y
Date : X1 Number : Y1
Date : X2 Number : Y2
答案 0 :(得分:0)
试试这个很简单的
$new_array = array();
for ($i=0; $i < 10; $i++) {
$date = Date('Y-m-d', strtotime("-$i days"));
$numar = $this->Misc->get($date);
// here a want to add to a array $date and $number
$new_array[] = array('Date' => $date, 'Number' => $numar );
}
答案 1 :(得分:0)
$arr_outupt = array();
for ($i=0; $i < 10; $i++) {
$date = Date('Y-m-d', strtotime("-$i days"));
$numar = $this->Misc->get($date);
$arr_output[] = array("date"=>$date, "number"=>$numar);
}
echo "<table>";
foreach($arr_output as $arr_temp)
{
echo "<tr>";
echo "<td>Date : </td>";
echo "<td>".$arr_temp['date']."</td>";
echo "<td>Number : </td>";
echo "<td>".$arr_temp['number']."</td>";
echo "</tr>";
}
echo "</table>";