2012-07-25 56 views
0

我很确定我只是在想这个,但现在我想不出其他任何方式。调用多维数组中的键/值

我有一个隐藏的字段,其中包含image_ids。隐藏字段的值看起来像“1076,1077,1078”

在我的控制,我这样做:

// get the value from hidden field 
    $image_string = $this->input->post('images'); 

    // create array from comma separated string 
    $images = explode(',', $image_string); 

    $image = array(); 

    // get image data from the database, returns an array of the database row 
    foreach ($images as $id) { 
     $image[$id] = $this->file_model->get_image_data($id); 
    } 

    print_r($image); 

当我做print_r(image);末,我得到这个:

Array (
[0] => stdClass Object ([image_id] => 1076) 
[1] => stdClass Object ([image_id] => 1077) 
[2] => stdClass Object ([image_id] => 1078) 
) 

这就是我卡住的地方。我需要做另一个foreach来回显每个image_id,但我无法弄清楚如何调用它。第二个foreach应该是什么样子?

回答

2

你有对象的数组,因此,所有你需要的是:

foreach($image as $obj) { 
    echo $obj->image_id; 
} 
+1

笑哇,我肯定这得太多。谢谢,这正是我所需要的 – Motive 2012-07-25 23:29:53

+0

你非常欢迎:) – nickb 2012-07-25 23:30:07