Posted By

jmiller on 08/19/10


Tagged

object array to convert


Versions (?)

Object to array


 / Published in: PHP
 

Pass in object. Returns array.

  1. function object_to_array($object){
  2. $new = NULL;
  3. if (is_object($object)) {
  4. $object = (array) $object;
  5. }
  6. if (is_array($object)) {
  7. $new = array();
  8. foreach ($object as $key => $val) {
  9. $key = preg_replace("/^\\0(.*)\\0/", "", $key);
  10. $new[$key] = $this->object_to_array($val);
  11. }
  12. } else {
  13. $new = $object;
  14. }
  15. return $new;
  16. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Sverri on August 21, 2010
$anObject = new AnObject();
$array = (array) $anObject;

Basically does the same thing.

You need to login to post a comment.