Please review the following code I am using:
<?php
$head = '[ { "status": "active", "confirmed_opt_in": null, "account_id": 1738888, "fields": { "first_name": "Ash", "last_name": "Wright" }, "member_id": 262268888, "last_modified_at": "@D:2016-12-30T19:58:25", "member_status_id": "a", "plaintext_preferred": false, "email_error": null, "member_since": "@D:2014-05-05T16:01:21", "bounce_count": 0, "deleted_at": null, "email": "[email protected]" } ]';
$data = json_decode($head,true); // the second param will cast it as array, default is obejct. See the linked docs of json_decode!
foreach($data as $item) {
$id=$item['member_id'];
$email=$item['email'];
echo "ID: $id EMAIL: $email<br/>";
// put your code here to write into DB or whatever you wanna do!
}
?>
In addition to the $id and $email variables I would also like to capture the first name and last name from the above JSON return in order to have variables for the first name and last name. Could someone please so me the syntax to accomplish this?