在代码点火器中一组学生详细信息检查前 - 每个循环,学生通过学生入学编号的基础获取
我的录取号码在 $ ad_no = $ this-> input-> post('adn_no'); : -
array(5){[0] => string(5)“11784”[1] => string(5)“11837”[2] => string(5)“11775”[3] => string(5)“11937”[4] => string(5)“12061”}
我尝试选择这些录取号码的学生,但结果只显示第一个学生的结果
我的代码:
foreach($ad_no as $key => $id) {
$this - > db - > where_in('ad_no', $id);
$query = $this - > db - > get('duration');
$r = $query - > result_array();
$dur = $r[0]['tot_hr'];
$start = explode(':', $dur);
$end = explode(':', $tm);
$total_hours = $start[0] - $end[0];
$total_hours1 = $start[1] - $end[1];
$mins = abs($total_hours1);
$dur = $total_hours.":".$mins;
$durs[$key] =
array(
'ad_no' => $ad_no[$key],
'tot_hr' => $dur
);
}
$reslt = $this - > Daily_temp_model - > duration($durs);
答案 0 :(得分:1)
在foreach循环中使用数组推送
$result=[];
foreach($ad_no as $key => $id) {
$this->db->where_in('ad_no', $id);
$query = $this-> db-> get('duration');
$r = $query-> result_array();
array_push($result, $r);
$dur = $r[0]['tot_hr'];
$start = explode(':', $dur);
$end = explode(':', $tm);
$total_hours = $start[0] - $end[0];
$total_hours1 = $start[1] - $end[1];
$mins = abs($total_hours1);
$dur = $total_hours.":".$mins;
$durs[$key] =
array(
'ad_no' => $ad_no[$key],
'tot_hr' => $dur
);
}
$reslt = $this->Daily_temp_model->duration($durs);
答案 1 :(得分:0)
使用in_array
<?php
$a = array('1.10', 12.4, 1.13);
if (in_array('12.4', $a, true)) {
echo "'12.4' found with strict check\n";
}
if (in_array(1.13, $a, true)) {
echo "1.13 found with strict check\n";
}
?>