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:

first_name;
?>

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 😉

Ubuntu server network problems – network down after reboot

I’ve experimented a strange situations a few days ago. After a few updates, my VPS became unreachable. Ifup command was throwing me errors – directory “/var/run/network” does not exists. After a few hours of researches, it seems that this is a problem that was solved back in 2008. Unfortunately, for some reasons – most probably because of updates the problem is back and i have no idea how to fix it – i’m not an expert. But, i tried the following thing that it’s working for me.

1. Create a .sh file with the following contents. Let’s name it network_check.sh

[prettify class=”bash”]

if [ ! -d “/var/run/network” ]; then

mkdir -p /var/run/network

sudo /etc/init.d/networking restart

sudo /etc/init.d/ssh restart

fi

[/prettify]

2. Create a cron to execute the script

[prettify class=”bash”]

*/1 * * * * root sh /PATH-TO-SCRIPT/network_check.sh

[/prettify]

As u can see i run the script every minute. You can set as much time as u want, but i like to be up and running immediate after reboot . Hope it helps someone 🙂

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 http://en.wikipedia.org/wiki/Web_development