I have the following issue: I would like to modify the elements of object. Accessing an element is working like:
foreach($ob as $element){echo $element->id;}
If I do the same
foreach($ob as $element){$element->id='XYZ';}
But this will not save into the object
I tried the following:
foreach($ob as &$element){$element->id='XYZ';}
But in this case i got the following error:
An iterator cannot be used with foreach by reference
Actually the $ob is a cakephp Query object looks like:
[
(int) 0 => object(App\Model\Entity\Document) {
'id' => (int) 26,'name'=>'Fax'}
(int) 1 => object(App\Model\Entity\Document) {
'id' => (int) 26,'name'=>'Email'}
]
and I want to modify the id's.
Thank you for your help.