objectToArray Part 2


/ Published in: PHP
Save to your folder(s)

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

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


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.