$timein_out = $this->time_model->get_timein_out($this->input->get('i'));
$total_diff= array();
$hours = array();
$mins =array();
foreach($timein_out as $timetest)
{
$total_diff[] = strtotime($timetest["Time_out"]) - strtotime($timetest["Time_in"]);
for($key=0;$key<count($total_diff);$key++)
{
$hours[] = intval(floor($total_diff[$key]/3600));
$mins[] = intval(($total_diff[$key]-$hours[$key]*3600)/60);
}
};
echo json_encode($total_diff); // output: [33600,34560,35160]
echo json_encode($hours); // [9,9,9,9,9,9]
echo json_encode($mins); //[20,20,36,20,36,46]
实际输出应该是
echo json_encode($hours); // [9,9,9,]
echo json_encode($mins); //[20,36,46]
问题:为什么输出重复?我的代码有什么问题?:( 谢谢。