foreach ($a as $key => $value) { $o->$key = $value; }
However, the syntax you use to declare your array is invalid. You need to do something like this:
$a = array('property1' => 1, 'property2' => 2);
If you don't need an object class, you can simply do this (by giving you an instance of stdClass ):
$o = (Object) $a;
source share