Posted By

satie83 on 03/22/12


Tagged

php object array


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

echipvina
Priestd09


PHP - Convert an object to an associative array


 / Published in: PHP
 

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

Converts a php object to an associative array

  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. }

Report this snippet  

You need to login to post a comment.