2016-05-02 88 views
0

無論數值的位置,我做array_search時,數組鍵總是輸出'1',請問我該如何糾正? 的「174」敵人例如array_search應該輸出4爲重點無法獲取陣列鍵

Array search of 174 print_r

<?php 

$sid = $this->db->get_where('student' , array('class_id' => $class_id))->result_array(); 

/** Get Mark of Each Student **/ 

foreach($sid as $rowm){ 
    $class_pos = $this->crud_model->get_exam_total($row2['exam_id'] , $class_id , $rowm['student_id']); 

    foreach($class_pos as $keys => $class_posi){ 

     $arr = $class_posi['mark_obtained']; 
     $arra = array($keys + 1=> $arr); 
     $resulte = array_search(174, $arra); 

     ?> 
     <td style="text-align: center;"><?php echo $resulte; ?></td> 
<?php }}?> 
+0

您還可以接受的答案,如果那種出了問題,對未來用戶很有用 –

回答

2

試試這個

<?php 

$sid = $this->db->get_where('student' , array('class_id' => $class_id))->result_array(); 

/** Get Mark of Each Student **/ 
$arra = array(); 

$arra[]=-1;// this will start index searching from 1 

foreach($sid as $rowm){ 


$class_pos = $this->crud_model->get_exam_total($row2['exam_id'] , $class_id , $rowm['student_id']); 


foreach($class_pos as $keys => $class_posi){ 

$arr = $class_posi['mark_obtained']; 
$arra[] = $arr; 
$resulte = array_search(174, $arra); 

?> 
<td style="text-align: center;"><?php echo $resulte; ?></td> 
<?php }}?> 
+0

輸出結果爲zer0 – 4Jean

+0

@ 4Jean啊右鍵進行了編輯,你能回顯$ arra以確保你有174分的標記是由學生獲得的嗎? –

+0

當我回聲$ arra它展示所有字段上的數組關鍵字'數組' – 4Jean