Here’s my code:
$get = $this->auth->current_user()->author->get_iterated();
foreach($get as $page) $pages[] = $page;
foreach($pages as $page) var_dump($page->title);
Now, if there are 2 pages that the user is author of, the latter foreach-loop will output the title of the last page 2 times.
I have a reason not to output the titles in the first loop. However, I don’t want to paste the whole code here, as the problem can be seen in the small code above.
It seems like $page is passed by reference to the array $pages. Is it possible to not do this, and save the static object instead?
Look into the
clonekeyword/magic method. This’ll create a separate copy of the object, which you can save or pass to wherever you need it…