Transformar objeto a array PHP


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

Esta función permite transformar un objeto a un array.


Copy this code and paste it in your HTML
  1. function object_to_array($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] = object_to_array($val);
  8. }
  9. }
  10. else $new = $mixed;
  11. return $new;
  12. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.