我有子陣的排列:轉換陣列子陣一個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));
但它是不好的做法。我怎樣才能達到這個結果?