I am working response from an API which returns data in JSON in a fairly straight forward structure. Pseudo structure is best represented as:
services -> service -> options -> option -> suboptions -> option
As this is decoded JSON, all of these are stdClass objects. I have a number of foreach statements iterating through the various services and options, which all work without issue. However, when I use a foreach statement at the suboption level, the object is serialized into a string. For your information suboptions has a structure like this.
[suboptions] => stdClass Object
(
[option] => stdClass Object
(
[code] => SOME_CODE
[name] => Some Name
)
)
When using a foreach such as this (where $option is an option in services -> service -> options -> option):
foreach($option->suboptions->option as $suboption) {
print_r($suboption);
}
It outputs
SOME_CODESome Name
Not the expected
stdClass Object
(
[code] => SOME_CODE
[name] => Some Name
)
I am not aware of any reasons foreach would do this in terms of depth or other conditions. I've tried everything I can think of and searched through SO and can't find any case of this happening. If anyone has any ideas I'd love to hear them! Cheers.
Apologies if it has been answered elsewhere or I am missing something obvious. If I have, it has escaped me thus far.
Edit: For those asking it is indeed the AusPost PAC API. Changing over from the DRC as it is being removed ~2014.