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


/ Published in: PHP

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


Copy this code and paste it in your HTML
  1. $array = array( 'one' => 1, 'two' => 2);
  2. $obj = json_decode(json_encode($array));

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.