我有子阵的排列:转换阵列子阵一个StdClass
$test = array("hello" => "world", "object" => array("bye" => "world"));
我想将它转换为对象:
$obj = (object) $test;
父阵列成为物体,但孩子还数组:
object(stdClass)[1]
public 'hello' => string 'world' (length=5)
public 'object' =>
array (size=1)
'bye' => string 'world' (length=5)
但我想是这样的:
object(stdClass)[1]
public 'hello' => string 'world' (length=5)
public 'object' =>
object(stdClass)[2]
public 'bye' => string 'world' (length=5)
这可能与此代码来达到:
$testObj = json_decode(json_encode($test));
但它是不好的做法。我怎样才能达到这个结果?