0
Array 
( 
    [0] => stdClass Object 
        ( 
            [fullname] => sample student 
            [nickname] => sample 
            [photo_ids] => |453 
            [gender] => MALE 
            [nationality] => KOREAN 
        ) 
    [1] => stdClass Object 
        ( 
            [fullname] => kim namkyun 
            [nickname] => tristan 
            [photo_ids] => |448 
            [gender] => MALE 
            [nationality] => KOREAN 
        ) 
)

I have this array and I wanted to get the name and value using foreach loop. BUT instead of getting the fullname and sample student for example. I get the 0 and the 1, This is the result from result() return in mysql.

My attempt:

$data->param_students = $this->student_model->getItems(array('status'=>'APPROVED'),array('fullname','nickname','photo_ids','gender','nationality'));
foreach ($data->param_students as $key=>$value) {
    print_r($key);
}
GGw
  • 413
  • 5
  • 18

2 Answers2

3

In below snippet you will get key and value you are looking for.

foreach ($data->param_students as $value) {
   foreach($value as $k => $v){
       echo $k.' '.$v;
   }
}
Rahul
  • 18,271
  • 7
  • 41
  • 60
2
$data->param_students = $this->student_model->getItems(array('status'=>'APPROVED'),array('fullname','nickname','photo_ids','gender','nationality'));
foreach ($data->param_students as $value) {
    print_r($value->fullname);
}
Shridhar
  • 339
  • 2
  • 15