Convert array to object in PHP

a simple way to convert array to object in PHP

PHP:
  1. <?php
  2.         function parseArrayToObject($array)
  3.     {
  4.        $object = new stdClass();
  5.        if (is_array($array) && count($array)> 0)
  6.        {
  7.           foreach ($array as $name=>$value)
  8.           {
  9.              $name = strtolower(trim($name));
  10.              if (!empty($name))
  11.              {
  12.                 $object->$name = $value;
  13.              }
  14.           }
  15.        }
  16.        return $object;
  17.     }

http://forum.weblivehelp.net/web-development/php-convert-array-object-and-vice-versa-t2.html

Related Articles

  • No Related Post
PHP

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>