我有一些像这样的变量:
$_8 = 0; $_9 = 0; $_10 = 0; $_11 = 0; $_12 = 0; $_13 = 0; $_14 = 0; $_15 = 0; $_16 = 0; $_17 = 0; $_18 = 0; $data = array();
然后我执行以下操作:
$vistoday = $app['db']->fetchAll('SELECT `Datum Bezoek 1` FROM `psttodo-uit` WHERE CAST(`Datum Bezoek 1` AS DATE) = CURRENT_DATE AND PB = 1');
foreach($vistoday as $v){
$date = strtotime($v['Datum Bezoek 1']);
$hours = (int)date('h', $date);
$minutes = (int)date('i', $date);
if($minutes > 30)
{
$hours = $hours + 1;
$count = ${"_" . $hours} + 1;
$data[$hours] = $count;
}
else
{
$data[$hours] = ${"_" . $hours}+1;
}
}
这些是我从数据库中提取的日期:
当我输出$ data时,我得到了这个:
array (size=2)
8 => int 1
9 => int 1
但通常键9的值应为2.所以他不增加,他只是加1而没有。有人可以帮我吗?
答案 0 :(得分:2)
Yoг不需要像$ _8
这样的变量foreach($vistoday as $v){
$date = strtotime($v['Datum Bezoek 1']);
$hours = (int)date('h', $date);
$minutes = (int)date('i', $date);
$hours = round($hours + $minutes / 61); // if $minutes > 30 ceil else floor
$data[$hours] = isset($data[$hours]) ? $data[$hours] + 1 : 1;
}