I have the following JSON in $ return:
{
"xml": "{
\"orders\":[
{
\"code\":\"PedidoTeste-1508156986545\",
\"channel\":\"PedidoTeste\",
\"placed_at\":\"2017-10-16T10:29:46-02:00\",
\"updated_at\":\"2017-10-16T10:29:46-02:00\",
\"total_ordered\":155.0,
\"interest\":0.0,
\"discount\":0.0,
\"shipping_cost\":0.0,
\"shipping_method\":\"Correios PAC\",
\"estimated_delivery\":\"2018-02-10T22:00:00-02:00\",
\"estimated_delivery_shift\":null,
\"shipping_address\":{
\"full_name\":\"Denis Moura\",
\"street\":\"Rua Sacadura Cabral\",
\"number\":\"130\",
\"detail\":\"\",
\"neighborhood\":\"Centro\",
\"city\":\"Rio de Janeiro\",
\"region\":\"RJ\",
\"country\":\"BR\",
\"postcode\":\"20081262\",
\"phone\":\"21 3722-3902\",
\"secondary_phone\":null
},
\"billing_address\":{
\"full_name\":\"Denis Moura\",
\"street\":\"Rua Sacadura Cabral\",
\"number\":\"130\",
\"detail\":\"\",
\"neighborhood\":\"Centro\",
\"city\":\"Rio de Janeiro\",
\"region\":\"RJ\",
\"country\":\"BR\",
\"postcode\":\"20081262\",
\"phone\":\"21 3722-3902\",
\"secondary_phone\":null
},
\"customer\":{
\"name\":\"Denis Moura\",
\"email\":\"[email protected]\",
\"date_of_birth\":\"1998-01-25\",
\"gender\":\"male\",
\"vat_number\":\"78732371683\",
\"phones\":[
\"21 3722-3902\"
]
}
}
]
}
}
I would like to use a FOREACH to print the CUSTOMER NAME and EMAIL of all requests within the ORDERS array (in this case there is only 1 request within the orders vector, but there could be several).
I'm trying:
foreach ($retorno->xml->orders as $pedido) {
print_r($pedido->customer->name);
echo "<br>";
print_r($pedido->customer->email);
}
return;
But I'm getting the error Trying to get property of non-object in the FOREACH line.
What would be the right way?