Nested arrays from curl response

fontaine1900

New member
I'm in array nightmare land over here. Scenario is a curl response from a API that looks to be three nested arrays. I don't do a lot with multidimensional arrays, so I'm struggling with parsing the correct results.

Example data / structure:

Code:
 Array (  => 1 [message] => The request succeeded [contacts] => Array ( [0] => Array ( [number] => example number [firstName] => example first name [lastName] => example last name [email] => test@email.com [contactId] => 648ed845a5c52f0be6be682e [status] => invalid [addedDate] => 06/18/2023 10:11 AM [unsubscribedDate] => [invalidDate] => 07/07/2023 08:06 PM [birthday] => ) [1] => Array ( [number] => etc etc

The API won't let me query just one phone number, so I have to return the entire list. What I am trying to do is grab the phone number and status out of this list.

I can grab the phone number using this code (after the successful curl request):

$result = curl_exec($curl);
$response = json_decode($result, true);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

// loop through arrays
foreach($response as $inner => $innerArray){
foreach($innerArray as $innerRow => $value){
foreach($value as $innerValue => $value2){
if ($innerValue == "number") {
if ($value2 == "1234567890") {
echo $value2;
} // end if
} // end if, echo phone number
}
}
}

While in the correct record, I need to also return the status so that I could echo a result like "1234567890 is active" or "... is unsubscribed", etc

Any pointers in the right direction would be appreciated!
Tim
 
Back
Top