简体   繁体   中英

Loop through 5 dimensional array in PHP

I have a json response as array

$responseArray['business_discovery']['media']['data'][0]['id']

I'm trying to loop through the 'data' element and grab the value of 'id' and place that into an array like

 $idarray[0] = $responseArray['business_discovery']['media']['data'][0]['id']

next iteration

 $idarray[1] = $responseArray['business_discovery']['media']['data'][1]['id']

What is the best loop to accomplish this?

You should be able to set data to a variable and loop through that.

$data = $responseArray['business_discovery']['media']['data'];
foreach($data as $item) {
    // do something with the id 
    $thisId = $item['id']
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM