I have an array with sub-array:
$test = array("hello" => "world", "object" => array("bye" => "world"));
I want to convert it to object:
$obj = (object) $test;
The parent array becomes object, but child is still array:
object(stdClass)[1]
public 'hello' => string 'world' (length=5)
public 'object' =>
array (size=1)
'bye' => string 'world' (length=5)
But I want to get something like this:
object(stdClass)[1]
public 'hello' => string 'world' (length=5)
public 'object' =>
object(stdClass)[2]
public 'bye' => string 'world' (length=5)
This could be reached with this code:
$testObj = json_decode(json_encode($test));
But it's bad practice. How can I reach this result?