In php, you can convert nested object to array in many ways.
- You can loop through the properties.
- You can (array) $object to change.
- Or create an entirely new one.
But things get messy with deeply nested object.
So, we have a little neat trick here.
To convert deeply nested objects to array, we can simply use json functions provided by php.
json_encode and json_decode are two of them.
Here, second parameter asks to turn your object to associative array.
Everything is awesome.