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
)
)
我有这个array
,我想使用foreach
循环来获取名称和值。但不要获取例如fullname
和sample student
。我得到了0
和1
,这是result()
返回mysql
的结果。
我的尝试
$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);
}
答案 0 :(得分:3)
在下面的代码段中,您将获得所需的键和值。
foreach ($data->param_students as $value) {
foreach($value as $k => $v){
echo $k.' '.$v;
}
}
答案 1 :(得分:1)
$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);
}