-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

7
  • 1
    You mean how to access single values or loop through each value? Commented Feb 19, 2016 at 11:59
  • what you want as an output? Commented Feb 19, 2016 at 11:59
  • To access totalResults for an example, you would do: echo $arrayname[2]['totalResults']. Commented Feb 19, 2016 at 12:00
  • It returns: Notice: Undefined offset: 2 Commented Feb 19, 2016 at 12:26
  • 1
    So as you can see it's $array['pageInfo']['totalResults'] Commented Feb 19, 2016 at 13:03

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

It returns: Undefined offset: 3

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.