Reputation: 765
The array key is always outputting '1' when i do the array_search no matter the position of value, please how do i correct this? Foe example array_search of '174' is supposed to output 4 as the key
<?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 }}?>
Upvotes: 0
Views: 48
Reputation: 2135
Try this
<?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 }}?>
Upvotes: 2