I am trying to extract and print a list of customers from the following json response.
Unfortunately it returns NULL
$customers_response = '{
"_embedded": {
"customers": [
{
"id": "1",
"firstName": "John",
"lastName": "Doe",
"email": "johndoe@nomail.net",
"type": "personal",
"status": "verified",
"created": "2021-06-06T05:00:09.923Z",
"address1": "99-99 33rd St",
"city": "Some City",
"state": "NY",
"postalCode": "11101"
},
{
"id": "2",
"firstName": "Jane",
"lastName": "Doe",
"email": "janedoe@nomail.net",
"type": "personal",
"status": "verified",
"created": "2021-06-06T05:00:09.923Z",
"address1": "99-99 33rd St",
"city": "Some City",
"state": "NY",
"postalCode": "11101"
}
]
},
"total": 1
}';
$customer_list = json_decode($customers_response)->{"_embedded"};
$customer_list = json_encode(json_decode($customer_list, true));
foreach ($customer_list["customers"] as $customer) {
$all_customers .= $customer{"id"}.": ".$customer{"firstName"}." ".$customer{"lastName"}."<br/>";
}
echo $all_customers;
I have tried the above code but it seems not to works. What do I need to change or is there any easier workaround to extract the list?