Posted By

dyteq on 12/16/10


Tagged

php object array line single convert associative


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

dyteq
Priestd09


Convert associative array to object (class) in a single line


 / Published in: PHP
 

URL: http://www.dyteq.com/2ndquest/?p=94

This method is easy to write, but not very efficient, as you can imagine.

  1. $array = array( 'one' => 1, 'two' => 2);
  2. $obj = json_decode(json_encode($array));

Report this snippet  

You need to login to post a comment.