Posted By

freezy on 07/26/11


Tagged

class object array function multidimensional


Versions (?)

multidimensional array to multidimensional object


 / Published in: PHP
 

  1. function arrayToObject($array, $class = 'stdClass') {
  2. if (!is_array($array)) {
  3. return $array;
  4. }
  5.  
  6. $object = new $class();
  7. foreach ($array as $key => $value) {
  8. $object->$key = self::arrayToObject($value);
  9. }
  10.  
  11. return $object;
  12. }

Report this snippet  

You need to login to post a comment.