PHP - Convert an object to an associative array


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

Converts a php object to an associative array


Copy this code and paste it in your HTML
  1. function object_to_array($data)
  2. {
  3. if(is_array($data) || is_object($data))
  4. {
  5. $result = array();
  6.  
  7. foreach($data as $key => $value) {
  8. $result[$key] = $this->object_to_array($value);
  9. }
  10.  
  11. return $result;
  12. }
  13.  
  14. return $data;
  15. }

URL: http://codesnippets.joyent.com/posts/show/1641

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.