If I do the following:
foreach ($extrasServices as $extras)
{
var_dump($extras);
}
I got this:
object(stdClass)#15 (3) {
["id"]=>
string(1) "1"
["optionname"]=>
string(16) "Disk Space"
["optiontype"]=>
string(1) "4"
}
object(stdClass)#18 (3) {
["id"]=>
string(1) "3"
["optionname"]=>
string(22) "Database (MySQL)"
["optiontype"]=>
string(1) "4"
}
object(stdClass)#19 (3) {
["id"]=>
string(1) "4"
["optionname"]=>
string(14) "Extra Domain"
["optiontype"]=>
string(1) "4"
}
On each of those object(stdClass) extras, I need to add an additional associative key, inside that associative key we should be able to store another array.
How can we accomplish something like this?
Thanks a lot
You should really treat the array of objects that you’re iterating over as what they are – objects – and use any setter method you have. (Or just set the property.)
As such:
However, you’ll also need to ensure that you’re accessing the objects via reference (otherwise they won’t change outside of the foreach iterator). Hence the &$extras in the foreach statement in the above example.