2017-09-14 58 views
2

代碼點火器一組學生的細節前,每個循環檢查,學生通過學生入園人數的基礎得到如何在codeigniter中檢查數組的條件?

我的錄取人數是$ ad_no = $這個 - >輸入 - >後(」 adn_no');: -

陣列(5){[0] =>串(5) 「11784」[1] =>串(5) 「11837」[2] => 串(5)「11775 「[3] =>串(5) 」11937「[4] =>串(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

'時間' 是一個表的名稱? – DFriend

+0

何時/何地設置了「$ tm」的值? – DFriend

+0

請爲此通話提供'$ dur'的示例值$ dur = $ r [0] ['tot_hr'];' – DFriend

回答

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); 
+0

爲什麼在箭頭' - >' – user4419336

+0

@ wolfgang1983之間有差距,它只是被php intrepreter忽略,這只是他的輸入風格。 –

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"; 
} 
?>