How to access array element? Why doesn't it work?

Good day!
I demanded of VoIP from zadarma statistics:
$answerObject = json_decode($answer);
if ($answerObject->status == 'success') {
print_r($answerObject->stats);
} else {
 echo $answerObject->message;
}

At the end in the html source code of the array(?): https://gist.github.com/anonymous/c7428d6f40475bbf...

1) How do I loop through such an array? (tried a few options, not fails)
2) How to see the value of [pbx_call_id], say 14 item for example?

P. S>> the Task, go through the array if [pbx_call_id] is a match I need to watch [sip] and [disposition], and depending on the values to perform a specific action.
3 day I suffer... help :(
July 4th 19 at 22:56
3 answers
July 4th 19 at 22:58
Solution
How can I sort this array?
foreach($answerObject->stats as $item) {
 echo $item->pbx_call_id, PHP_EOL;
}
you have an array of objects. therefore, with the array working with array and objects like object.
it turned out in the end? - kavon.Murphy commented on July 4th 19 at 23:01
Yes. Thank you. What means as? - Hosea.Cartwright commented on July 4th 19 at 23:04
: this is part of the foreach syntax. - kavon.Murphy commented on July 4th 19 at 23:07
July 4th 19 at 23:00
How to watch the value of [pbx_call_id], say 14 item for example?

$arr = $answerObject->stats;
echo $arr[14][pbx_call_id];


The challenge, walk the array if [pbx_call_id] is a match I need to watch [sip] and [disposition], and depending on the values to perform a specific action.

$nuznii_pbx_call_id = 123;
$arr = $answerObject->stats;
$sip = false;
foreach($arr as $one){
if($one['pbx_call_id'] == $nuznii_pbx_call_id){
$sip =$one['sip'];
}
}
if($sip){
echo $sip;
}else{
echo 'no matches found';
}
and here and there) - kavon.Murphy commented on July 4th 19 at 23:03
The problem is, that I did, but no result... :( - Hosea.Cartwright commented on July 4th 19 at 23:06
: empty? error? What? - kavon.Murphy commented on July 4th 19 at 23:09
: again this is an array of objects, not an array of arrays. - kavon.Murphy commented on July 4th 19 at 23:12
: then you can take an old recipe:
object_to_array function($data)
{
 if (is_array($data) || is_object($data))
{
 $result = array();
 foreach ($data as $key => $value)
{
 $result[$key] = object_to_array($value);
}
 return $result;
}
 return $data;
}
- Hosea.Cartwright commented on July 4th 19 at 23:15
and a cart with a running start. but why? if you can safely work with objects.
but if you really want an array, then json_decode has a second parameter. - Henderson_Beat commented on July 4th 19 at 23:18
: Yes, that is correct - kavon.Murphy commented on July 4th 19 at 23:21
July 4th 19 at 23:02
$answerObject you do not object and array of objects as answerObject[1]->status

php.net/manual/ru/control-structures.foreach.php

Find more questions by tags ArraysPHP