$a = new stdclass;
$a->zone1 = array();
$a->zone1[0] = new stdclass;
$a->zone1[0]->id = "123";
$a->zone1[0]->owner = "234";
Alternatively, relying upon the fact that arrays are converted to stdClass objects when casted into objects:
$a = (object) array(
"zone1" => array(
(object) array("id" => "123", "owner" => "234"),
),
);
For this, var_export
gives:
stdClass::__set_state(array(
'zone1' =>
array (
0 =>
stdClass::__set_state(array(
'id' => '123',
'owner' => '234',
)),
),
))
Note that, has Daniel has pointed out, stdClass
doesn't actually have a __set_state
method. I supposed you were just exemplifying the structure of the variable by giving the output of var_export
. Serialization should be done with serialize
instead.