So, I'm using an API that spits out info in JSON, (basically) in this format:
{"linkId":"1234asdf","clickData"
["member":{"userId":"asdf1234","email":"[email protected]","firstName":"Joe","lastName":"Schmoe"}]},
["member":{"userId":"fdsa4321","email":"[email protected]","firstName":"Moreo","lastName":"Hater"}],
--for each link in an email campaign. I want to pull this data via a nested for loop & organize it like so:
$linkCount = count($linkArray); //from previous API call
for ($i = 0; $i < $linkCount; $i++) {
$clickReport[] = //API call here; omitted for brevity
//parse the JSON here to get $linkid, $url; omitted for brevity
$memberCount = substr_count($clickReport[$i],'"member":'); //to count number of people listed in JSON response
for ($j = 0; $j < $memberCount; $j++) {
//parse the JSON here to get $euid, $fname, $lname, $email; omitted for brevity
$clickers[] = array (
$euid[$i] => array (
'fname' => $fname[$j],
'lname' => $lname[$j],
'email' => $email[$j],
'links' => array (
'linkid' => $linkid[$i],
'url' => $url[i],
),
),
);
}
}
The issue I am having is if one member clicks more than one link, the nested for loop overwrites the previous 'links' => array(). How can I write this such that links is added to, rather than overwritten?
json_encodeandjson_decode?json_decodeoff, and I found it easier to just parse it myself rather than fix it forjson_decode. Thanks for throwing that out there, though!!