I have an array with three keys and values. I need to convert first two keys into an object and the 3rd must remain an array but with and object inside it.
My Array:
$person = array(
'name' => 'bob',
'surname' => 'white',
'address' => array(
'street' => 'green road',
'houseNo' => '89',
'city' => 'Liverpool'
)
);
I want to convert this array into an object like so:
$personInformation = json_decode(json_encode($person));
Which gives me this:
object(stdClass)(3)
{
'name' => 'bob',
'surname' => 'white',
'address' => object(stdClass)(3)
{
'street' => 'green road',
'houseNo' => '89',
'city' => 'Liverpool'
}
}
But what I am after is this:
object(stdClass)(3)
{
'name' => 'bob',
'surname' => 'white',
'address' => array(
object(stdClass)(3)
{
'street' => 'green road',
'houseNo' => '89',
'city' => 'Liverpool'
}
)
}
I'm really stuck on how to get this middle part sorted.