Posted By

frederichoule on 04/01/11


Tagged

object array encode json convert decode


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

frederichoule


Object to Array


 / Published in: PHP
 

  1. function object2array($mixed) {
  2. if(is_object($mixed)) $mixed = (array) $mixed;
  3. if(is_array($mixed)) {
  4. $new = array();
  5. foreach($mixed as $key => $val) {
  6. $key = preg_replace("/^\\0(.*)\\0/","",$key);
  7. $new[$key] = object2array($val);
  8. }
  9. }
  10. else $new = $mixed;
  11. return $new;
  12. }

Report this snippet  

You need to login to post a comment.