Dorvalla
Dorvalla

Reputation: 5240

retrieve specific key value from multidimensional array

I have the following array, since i converted the string i got back from a SOAP call to an array:

Array
(
    [soapenvBody] => Array
        (
            [queryRequestsResponse] => Array
                (
                    [result] => Array
                        (
                            [0] => Array
                                (
                                    [BCRcustomId] => REQ16569
                                    [BCRexternalId] => Array
                                        (
                                        )

                                    [BCRrecordId] => a035700001CM60kAAD
                                    [BCRrequestId] => a1J5700000857EYEAY
                                )

                            [1] => Array
                                (
                                    [BCRcustomId] => SRQ100784
                                    [BCRexternalId] => Array
                                        (
                                        )

                                    [BCRrecordId] => a033E000001PxfAQAS
                                    [BCRrequestId] => a1J3E0000000GSaUAM
                                )

                        )

                )

        )

)

I am trying to retrieve the BCRrecordId, since I need that item to make another SOAP call. I tried the following

function getID($array) {
    return $array['BCRcustomId'];
}   

//

$arr = array_map('getID', $array );
print_r($arr);

Now i get an error back on this saying it doesnt find it.

Undefined index: BCRcustomId in index.php on line 97
[soapenvBody] => )Array (

My assumption is that it doenst go lower than 1 level in the array. Now i am not familair with these kinds of arrays, how would I solve this? By multiple for each loops? Or is there another way to retrieve these items

Upvotes: 0

Views: 48

Answers (1)

Alex Blex
Alex Blex

Reputation: 37028

If $array is the whole response, you need to pass only result part of it:

$arr = array_map('getID', $array['soapenvBody']['queryRequestsResponse']['result']);

Upvotes: 3

Related Questions