S
S
stickmann2016-08-17 11:07:30
PHP
stickmann, 2016-08-17 11:07:30

Multidimensional arrays, how to pull the last one?

I have the following json

{
    "previous": null,
    "results": [
        {
            "id": 4471,
            "ru_title": "Озеро на Клинтон-роуд",
            "orig_title": "The Lake on Clinton Road",
            "imdb_id": "tt2662764",
            "kinopoisk_id": "738141",
            "created": "2016-08-17T05:46:30.058687Z",
            "released": "2015-07-17",
            "media": [
                {
                    "id": 12704,
                    "translation": {
                        "id": 26,
                        "title": "Любительский (многоголосый закадровый)"
                    },
                    "source_quality": "webdl",
                    "max_quality": 360,
                    "created": "2016-08-17T05:50:28.131223Z",
                    "accepted": "2016-08-17T06:20:02.219984Z",
                    "path": "http://site.ru/784d7aad6e91ea7f401ea5e3b63431fe1eff1f63/",
                    "hls": "http://site.ru/784d7aad6e91ea7f401ea5e3b63431fe1eff1f63/hls.m3u8",
                    "qualities": [
                        {
                            "url": "http://site.ru/784d7aad6e91ea7f401ea5e3b63431fe1eff1f63/360.mp4",
                            "hls": "http://site.ru/784d7aad6e91ea7f401ea5e3b63431fe1eff1f63/360.m3u8",
                            "resolution": 360
                        },
                        {
                            "url": "http://site.ru/784d7aad6e91ea7f401ea5e3b63431fe1eff1f63/240.mp4",
                            "hls": "http://site.ru/784d7aad6e91ea7f401ea5e3b63431fe1eff1f63/240.m3u8",
                            "resolution": 240
                        }
                    ],
                    "screens": [
                        "http://site.ru/784d7aad6e91ea7f401ea5e3b63431fe1eff1f63/thumb001.jpg",
                        "http://site.ru/784d7aad6e91ea7f401ea5e3b63431fe1eff1f63/thumb002.jpg",
                        "http://site.ru/784d7aad6e91ea7f401ea5e3b63431fe1eff1f63/thumb003.jpg",
                        "http://site.ru/784d7aad6e91ea7f401ea5e3b63431fe1eff1f63/thumb004.jpg",
                        "http://site.ru/784d7aad6e91ea7f401ea5e3b63431fe1eff1f63/thumb005.jpg"
                    ],
                    "duration": 4765
                }
            ]
        }
    ],
    "next": "https://site.ru/api/v1/movies/?limit=1&offset=1"
}

How to pull everything deeper than results[media]?
That's what I suffered =)
$output = curl_exec($ch);
$a = json_decode($output);

foreach ($a as $array) {
    foreach ($array[0] as $key=>$value) {
      echo " <b>".$key."</b>".": ".$value;
        foreach (?????) {
          echo ?????
        }
    }
}

I'm not going any further...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pretor DH, 2016-08-17
@stickmann

yourarray->results[0]->media[0]
in your code

$output = curl_exec($ch);
$a = json_decode($output,true);

foreach ($a as $array) {
    foreach ($array[0] as $key=>$value) {
      if ( is_array($value) ) {
        foreach ($value[0] as $k=>$v) {
          echo " <b>".$k."</b>".": ".$v;
        }
      } else {
         echo " <b>".$key."</b>".": ".$value;
      }
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question