-3

I am working with response from Youtube Data API and I don't know how to read each values in the array.

Array
(
[0] => youtube#channelListResponse
[1] => "X"
   [2] => Array (
                 [totalResults] => 1
                 [resultsPerPage] => 1
                )
[3] => Array (
    [0] => Array
        (
          [kind] => youtube#channel
          [etag] => "XX"
          [id] => XXX
            )
        )
)

When I try to access [id] with echo $array[3]['id'] it returns Notice: Undefined offset: 3

khalnas
  • 47
  • 7

1 Answers1

0

AS Max said you can access single value in array in array by

$arrayName[index]['key']

Example You can access 'kind' with

$arrayName[3]['kind']

Since, inner level array is key value paired you need to specify key instead of index. If you want to access all value, you can do it with foreach loop and check type of each value use'gettype()' method. if type is array then use same function recursively.

Pritam Narkhede
  • 163
  • 1
  • 9