How to convert an object in to an array in PHP?

It felt like a big deal to me few months ago until I personally came across a situation like this.
In my mind I thought turning an object in to an array required sort of looping or some sort of tricky codes involved.

But when I did a little research I found out its not a big deal at all!

Only a single line of code dose the whole job!



solution is type casting.

$phpArray =  (array) $phpObject;

See how easy it is.

Once I sow this in Stackoverflow I was blown away.

While having such an easy solutions I spent so much of time on hard methods.

I hope this trick would help you guys on your projects as well.
:)

Thanks for reading,

No comments:

Post a Comment