Posted By

jgomez on 03/28/12


Tagged

php object array function to


Versions (?)

objectToArray Part 2


 / Published in: PHP
 

URL: http://www.sitepoint.com/forums/showthread.php?438748-convert-object-to-array

If you want to use this in a class, change the last line to:

return array_map(array($this, __FUNCTION__), $object );

  1. function objectToArray($object)
  2. {
  3. if(!is_object( $object ) && !is_array( $object ))
  4. {
  5. return $object;
  6. }
  7. if(is_object($object) )
  8. {
  9. $object = get_object_vars( $object );
  10. }
  11. return array_map('objectToArray', $object );
  12. }

Report this snippet  

You need to login to post a comment.