Object to array


/ Published in: PHP

Pass in object. Returns array.


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

You need to login to post a comment.