Convert multidimensional array to object – PHP

As you may already know, you can convert an array into an object simple like this:

 'John', 'last_name' => 'Doe');
    $object = (object) $array;

Then you call the object:


The problem is that you can’t do this with multidimensional array. So, for this, i’ve found the solution:

 0) {
      foreach ($array as $name=>$value) {
         $name = strtolower(trim($name));
         if (!empty($name)) {
            $object->$name = arrayToObject($value);
      return $object;
    else {
      return FALSE;

// Now we can test the method
$array = array(
    'f_name' => 'Rada',
    'l_name' => 'Calin',
    'age' => 26,
    'parents' => array(
        'mom' => array(
            'f_name' => 'Rada',
            'l_name' => 'Daniela',
            'age' => 45,
        'dad' => array(
            'f_name' => 'Rada',
            'l_name' => 'Ioan',
            'age' => 46,

// Convert the array to object
$user = arrayToObject($array);

// Example output
echo $user->parents->mom->l_name;

Hope this is helpful 😉

What is Web Development

Web development is a broad term for the work involved in developing a web site for the Internet (World Wide Web) or an intranet (a private network). This can include web design, web content development, client liaison, client-side/server-side scripting, web server and network security configuration, and e-commerce development.

However, among web professionals, “web development” usually refers to the main non-design aspects of building web sites: writing markup and coding. Web development can range from developing the simplest static single page of plain text to the most complex web-based internet applications, electronic businesses, or social network services.
For larger organizations and businesses, web development teams can consist of hundreds of people (web developers). Smaller organizations may only require a single permanent or contracting webmaster, or secondary assignment to related job positions such as a graphic designer and/or information systems technician. Web development may be a collaborative effort between departments rather than the domain of a designated department.


Check more info at