0

I'm pretty sure I'm just overthinking this but I can't think of any other ways right now.

I have a hidden field that contains image_ids. The value of the hidden field looks like "1076,1077,1078"

In my Controller, I am doing this:

    // 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);

When I do the print_r(image); at the end, I get this:

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

This is where I'm stuck. I need to do another foreach to echo out each image_id, but I can't figure out how to call it. What should the 2nd foreach look like?

1 Answer 1

2

You have an array of objects, so all you need is:

foreach( $image as $obj) {
    echo $obj->image_id;
}
Sign up to request clarification or add additional context in comments.

1 Comment

lol wow, I was definitely overthinking this. thanks, that's exactly what I needed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.