PHP initialize objects like arrays

In PHP, you can initialize arrays with values quickly using the following notation:

$array = array("name" => "member 1", array("name" => "member 1.1") ) ....

To initialize objects, use STDClass

$object = new STDClass();

To quickly initialize objects like arrays, we can do:

$object = (object) array("name" => "member 1", array("name" => "member 1.1") );

By Keenlio, May 20, 2014

What do you think?

Leave a Reply

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


− 7 = zero

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>