PHP looping through array and appending to object

Viewed 836

I have array of objects like so;

Array
(
    [0] => stdClass Object
        (
            [Job] => stdClass Object
                (
                    [ID] => 123
                    [Name] => Foo
                 )
        )
    [1] => stdClass Object
        (
            [Job] => stdClass Object
                (
                    [ID] => 456
                    [Name] => BAR
                 )
        )
)

I need to loop through the array and append some additional information to the object like 'Status', but I'm having some issues.

foreach($arrJobs as $key => $val) {

  $arrJobs[$key]->Job->Status = new StdClass;
  $arrJobs[$key]->Job->Status = $myStatus;

}

This appears to work, but I get the following warning;

Warning: Creating default object from empty value in...

4 Answers
Related