Press "Enter" to skip to content

Convert your deeply nested objects to array

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.



  1. July 19, 2018

    Your style is really unique compared to other people I have read stuff from.

    Thank you for posting when you’ve got the opportunity, Guess
    I will just bookmark this web site.

  2. July 19, 2018

    Thank you for sharing your info. I really appreciate your efforts
    and I will be waiting for your further post thanks once again.

Leave a Reply

Your email address will not be published.