Joined May 2012
·
Posted to
PHP - Convert mixed array & objects recursively
over 1 year
ago
Whoops. I should have probably included that this applies to mixed multidimensional arrays and objects. Type casting would only work at the top level and not apply to the children.
** I edited the tip to reflect that I originally intended.
Achievements
349 Karma
23,801 Total ProTip Views
Nephila Komaci 3
Have at least three original repos where PHP is the dominant language
Forked
Have a project valued enough to be forked by someone else
Cub
Have at least one original jQuery or Prototype open source repo
Walrus
The walrus is no stranger to variety. Use at least 4 different languages throughout all your repos
Kona
Have at least one original repo where CoffeeScript is the dominant language
Yes, you can type cast a single object or array. The point here is to do it recursively over a large array/object set.
Personally, I prefer to work with objects so this comes in handy to convert a multidimensional array into a series of parent/child objects. I have also run across instances of receiving large object sets where it makes more sense to work with arrays. That's where this comes in handy.