convertion: array to object, object to array


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



Copy this code and paste it in your HTML
  1. // Funcion de Objeto a Array
  2. function object_to_array($object)
  3. {
  4. if(is_array($object) || is_object($object))
  5. {
  6. $array = array();
  7. foreach($object as $key => $value)
  8. {
  9. $array[$key] = object_to_array($value);
  10. }
  11. return $array;
  12. }
  13. return $object;
  14. }
  15.  
  16. // Funcion de Array a Objeto
  17. function array_to_object($array = array())
  18. {
  19. return (object) $array;
  20. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.