How to parse multidimensional json array in php?

Good day, get rest api json array of the following form.
data {
calls
{
 "id": "7e734dc1-544d-4f04-8ccc-8bd5b197a88c",
 "caller": 
{
 "name": "u2 by u2",
 "extension": "101"
},
 "called": 
[
{
 "isConnected": true,
 "name": "akmightycall4 akmightycall4",
 "extension": "100"
},
{
 "isConnected": false,
 "name": "u3 u3",
 "extension": "102",
 "phone": "+75551112235"
}
],
 "businessNumber": "+74950152729",
 "dateTimeUtc": "2018-06-05T13:38:29.522 Z",
 "duration": "23066",
 "direction": "Outgoing",
 "callStatus": "Connected",
 "callRecord": 
{
 "fileName": "records/T1U9Y5b197a88c.wav",
 "uri": "http://localhost/u2.wav?recordid=fdaVn2YWttaWdodHljYWxGV20"
}
}
}


I'm using the following code can get the values that come after the calls of type id:
$json = json_decode($result, true);

foreach($json['data']['calls'] as $item) {
print $item['id'];
print '<br>';
}

But I don't understand how I can get values from called and caller. Please explain.
March 23rd 20 at 18:40
1 answer
March 23rd 20 at 18:42
var_dump($item)...
Whether to display the loop inside the loop in this case?
foreach($json['data']['calls'] as $item) {
 foreach($item['called'] as $p) {
 echo $p['name'];
}
 }
- ernesto.Baumbach commented on March 23rd 20 at 18:45
@ernesto.Baumbachand what better way to iterate over nested arrays? cycle in cycle in cycle.
I came with a huge json nesting,about 7 loops inside each other. - hailey86 commented on March 23rd 20 at 18:48
@hailey86, I thought there is some easier and more elegant solution :( - ernesto.Baumbach commented on March 23rd 20 at 18:51
@ernesto.Baumbach, do your function, which will be in your elegant. Standard features, not to cover all the decisions. - tracey_Ku commented on March 23rd 20 at 18:54
@ernesto.Baumbach, Support @tracey_Ku , yank function,maybe even recursive, with checks on the array, and all the consequences. - hailey86 commented on March 23rd 20 at 18:57

Find more questions by tags JSONPHP