I have a PHP array object that can contain zero or more values like this:
Array
(
[0] => stdClass Object
(
[id] => dkgasO05P2XpfyWW
)
[1] => stdClass Object
(
[id] => LzE6G9UQIShOUoKq
)
)
I want to loop through each value in this array and use the id in a query that returns an object that looks like this:
Array
(
[0] => stdClass Object
(
[id] => taWPlKGXHR5Y03cc
[title] => Test Document Title
[filename] => test.docx
)
)
On each iteration of the loop the query returns with one result in the form of an array object. I want to add the object to an array object that in this case would look something like this:
Array
(
[0] => stdClass Object
(
[id] => dkgasO05P2XpfyWW
[title] => Test Document Title 0
[filename] => test0.docx
)
[1] => stdClass Object
(
[id] => LzE6G9UQIShOUoKq
[title] => Test Document Title 1
[filename] => test1.docx
)
)
The query is written and working and I know I need to use a foreach loop to iterate over the array of IDs, but I don't quite get how to set it up so that the end result is an array object as listed just above. I'm using PHP & Codeigniter to do all of this.
The code of the foreach I have so far is something like this:
$child = array();
foreach ($id as $row) {
$child = $this->users_model->get_docnfo($id);
}
Thanks for reading!