multidimensional array to multidimensional object


/ Published in: PHP



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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.