Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jhutto's avatar

Processing API array with multi-dimensional array

I'm working on an app, that is pulling data from an API of an online application we use. I retrieving this long array from the app but I'm still new to this and not sure what's the best way to process the multi-dimensional array. This issue is getting to the data that is buried deep within the array. Any ideas you be helpful.

I've tried create a single array and but then I can't seem to get the foreach loop inside of the inserting the data into another array...

I need to be able to process through theses sections which have multiple records. "addresses" => array:2 [▶] "communications" => array:3 [▶]

Here's the data that is being returned....

array:4 [▼
  0 => array:40 [▼
    "@id" => "1075701652"
    "@uri" => "https://milehi.staging.fellowshiponeapi.com/v1/People/1075701652"
    "@imageURI" => ""
    "@oldID" => "23260046"
    "@iCode" => "q2B9Wy7iRRK7F8b2C5DfKg=="
    "@householdID" => "1046151597"
    "@oldHouseholdID" => "15023395"
    "title" => null
    "salutation" => null
    "prefix" => null
    "firstName" => "Michael"
    "lastName" => "Angel"
    "suffix" => null
    "middleName" => null
    "goesByName" => null
    "formerName" => null
    "gender" => "Male"
    "dateOfBirth" => "2005-04-07T00:00:00"
    "maritalStatus" => "Child/Yth"
    "householdMemberType" => array:3 [▶]
    "isAuthorized" => "true"
    "status" => array:6 [▶]
    "occupation" => array:4 [▶]
    "employer" => null
    "school" => array:3 [▶]
    "denomination" => array:3 [▶]
    "formerChurch" => null
    "barCode" => null
    "memberEnvelopeCode" => null
    "defaultTagComment" => null
    "weblink" => array:3 [▶]
    "solicit" => null
    "thank" => "true"
    "firstRecord" => "2009-01-30T09:37:22"
    "attributes" => array:1 [▶]
    "addresses" => array:1 [▶]
    "communications" => array:1 [▶]
    "lastMatchDate" => null
    "createdDate" => "2015-12-14T12:07:53"
    "lastUpdatedDate" => "2015-12-14T12:07:53"

Thanks for your help.

0 likes
1 reply
jhutto's avatar

Sorry... meant to put what I tried... It's not working.

foreach($persons as $key => $value){

           


           $data[$key] = array(
               "@id" => $value['@id'],
               "FirstName" => $value['firstName'],
               "middleName" => $value['middleName'],
               "goesByName" => $value['goesByName'],
               "gender" => $value['gender'],
               "address1" => $value['addresses']['address']['0']['address1'],
               "address2" => $value['addresses']['address']['0']['address2'],
               "city" => $value['addresses']['address']['0']['city'],
               "state" => $value['addresses']['address']['0']['stProvince'],
               "zip" => $value['addresses']['address']['0']['postalCode'],
               "householdposition" => $value['householdMemberType']['name'],
               "status" => $value['status']['name'],
            
            );
            
            $Communications = $value['Communications']['Communication'];
            foreach($Communications as => $Communication){

                $datacommunications = array(
                    "householdposition" => $value['householdMemberType']['name'],

                );


            }
           
            
        };

Please or to participate in this conversation.