Help deal with an array

there is such an array bitriksa24 -

{ "result": [{ "ID": "150", "EMAIL": [{ "ID": "172", "VALUE_TYPE": "WORK", "VALUE": "666@666.666", "TYPE_ID": "EMAIL" } ] } ], "total": 1, "time": { "start": 1515742416.5858, "finish": 1515742416.6568, "duration": 0.070952892303467, "date_start": "2018-01-12T10:33:36+03:00", "date_finish": "2018-01-12T10:33:36+03:00" } } 

I can not pick up the "ID":"172" and "VALUE":"666@666.666"

I'm writing - echo $result['result'][0]['ID'] - displays 150 ( "ID":"150" ) everything is correct.
And when I write this echo $result['result'][0]['ID']['EMAIL'][0]['ID'] instead of "ID":"172" - 1 output for me

help to deal with the array, gentlemen. Maybe there is an easier way to output the elements of an array?

  • one
    because it is not an array, but json string, which must first be converted into an array $result = json_decode($str, true) - Alexey Shimansky
  • Attach print_r($result); to the question print_r($result); - Alexey Shatrov
  • @ Alexey Shimansky - perhaps Bitrix already somehow handles this line in its own way. - Alexey Shatrov
  • Judging from 1AlexeyShatrov, it is unlikely. You can advise the TS to use debugging and see what it does)) https://ru.stackoverflow.com/questions/701142/How-like-means-find-error-in-php-code - Alexey Shimansky

2 answers 2

 $str = '{"result":[{"ID":"150","EMAIL":[{"ID":"172","VALUE_TYPE":"WORK","VALUE":"666@666.666","TYPE_ID":"EMAIL"}]}],"total":1,"time":{"start":1515742416.5858,"finish":1515742416.6568,"duration":0.070952892303467,"date_start":"2018-01-12T10:33:36+03:00","date_finish":"2018-01-12T10:33:36+03:00"}}'; $data = json_decode($str, true); $id = $data['result'][0]['ID']; $email = $data['result'][0]['EMAIL'][0]['VALUE']; var_dump($id, $email); 
  • Thanks for the detailed answer! - Archi Savin

why are you writing

 $result['result'][0]['ID']['EMAIL'][0]['ID'] 

if needed

 $result['result'][0]['EMAIL'][0]['VALUE'] 

?

  • Thanks for the found jamb! - Archi Savin