过滤和限制数组

时间:2017-02-05 12:40:54

标签: php arrays json api

我使用tmdb.org的API来检索电影数据。不过,他们的学分作为单独的回复返回。我希望能够只显示Director和前10个演员。我如何在JSON响应中操纵该数据?

以下是返回内容的摘录。我删除了很多学分,所以它不会那么长。



array(26) {
  ["adult"]=>
  bool(false)
  ["backdrop_path"]=>
  string(32) "/4iJfYYoQzZcONB9hNzg0J0wWyPH.jpg"
  ["belongs_to_collection"]=>
  array(4) {
    ["id"]=>
    int(10)
    ["name"]=>
    string(20) "Star Wars Collection"
    ["poster_path"]=>
    string(31) "/ghd5zOQnDaDW1mxO7R5fXXpZMu.jpg"
    ["backdrop_path"]=>
    string(32) "/d8duYyyC9J5T825Hg7grmaabfxQ.jpg"
  }
  ["budget"]=>
  int(11000000)
  ["genres"]=>
  array(3) {
    [0]=>
    array(2) {
      ["id"]=>
      int(12)
      ["name"]=>
      string(9) "Adventure"
    }
    [1]=>
    array(2) {
      ["id"]=>
      int(28)
      ["name"]=>
      string(6) "Action"
    }
    [2]=>
    array(2) {
      ["id"]=>
      int(878)
      ["name"]=>
      string(15) "Science Fiction"
    }
  }
  ["homepage"]=>
  string(61) "http://www.starwars.com/films/star-wars-episode-iv-a-new-hope"
  ["id"]=>
  int(11)
  ["imdb_id"]=>
  string(9) "tt0076759"
  ["original_language"]=>
  string(2) "en"
  ["original_title"]=>
  string(9) "Star Wars"
  ["overview"]=>
  string(312) "Princess Leia is captured and held hostage by the evil Imperial forces in their effort to take over the galactic Empire. Venturesome Luke Skywalker and dashing captain Han Solo team together with the loveable robot duo R2-D2 and C-3PO to rescue the beautiful princess and restore peace and justice in the Empire."
  ["popularity"]=>
  float(9.414021)
  ["poster_path"]=>
  string(32) "/tvSlBzAdRE29bZe5yYWrJ2ds137.jpg"
  ["production_companies"]=>
  array(2) {
    [0]=>
    array(2) {
      ["name"]=>
      string(9) "Lucasfilm"
      ["id"]=>
      int(1)
    }
    [1]=>
    array(2) {
      ["name"]=>
      string(38) "Twentieth Century Fox Film Corporation"
      ["id"]=>
      int(306)
    }
  }
  ["production_countries"]=>
  array(1) {
    [0]=>
    array(2) {
      ["iso_3166_1"]=>
      string(2) "US"
      ["name"]=>
      string(24) "United States of America"
    }
  }
  ["release_date"]=>
  string(10) "1977-03-20"
  ["revenue"]=>
  int(775398007)
  ["runtime"]=>
  int(121)
  ["spoken_languages"]=>
  array(1) {
    [0]=>
    array(2) {
      ["iso_639_1"]=>
      string(2) "en"
      ["name"]=>
      string(7) "English"
    }
  }
  ["status"]=>
  string(8) "Released"
  ["tagline"]=>
  string(44) "A long time ago in a galaxy far, far away..."
  ["title"]=>
  string(9) "Star Wars"
  ["video"]=>
  bool(false)
  ["vote_average"]=>
  float(7.9)
  ["vote_count"]=>
  int(4584)
  ["credits"]=>
  array(2) {
    ["cast"]=>
    array(106) {
      [0]=>
      array(7) {
        ["cast_id"]=>
        int(3)
        ["character"]=>
        string(14) "Luke Skywalker"
        ["credit_id"]=>
        string(24) "52fe420dc3a36847f8000441"
        ["id"]=>
        int(2)
        ["name"]=>
        string(11) "Mark Hamill"
        ["order"]=>
        int(0)
        ["profile_path"]=>
        string(32) "/ws544EgE5POxGJqq9LUfhnDrHtV.jpg"
      }
      [1]=>
      array(7) {
        ["cast_id"]=>
        int(4)
        ["character"]=>
        string(8) "Han Solo"
        ["credit_id"]=>
        string(24) "52fe420dc3a36847f8000445"
        ["id"]=>
        int(3)
        ["name"]=>
        string(13) "Harrison Ford"
        ["order"]=>
        int(1)
        ["profile_path"]=>
        string(32) "/aVKNqtkzZCymupOrvwxozamRyVc.jpg"
      }
      [2]=>
      array(7) {
        ["cast_id"]=>
        int(5)
        ["character"]=>
        string(20) "Princess Leia Organa"
        ["credit_id"]=>
        string(24) "52fe420dc3a36847f8000449"
        ["id"]=>
        int(4)
        ["name"]=>
        string(13) "Carrie Fisher"
        ["order"]=>
        int(2)
        ["profile_path"]=>
        string(32) "/pbleNurCYdrLFQMEnlQB2nkOR1O.jpg"
      }
      [3]=>
      array(7) {
        ["cast_id"]=>
        int(6)
        ["character"]=>
        string(17) "Grand Moff Tarkin"
        ["credit_id"]=>
        string(24) "52fe420dc3a36847f800044d"
        ["id"]=>
        int(5)
        ["name"]=>
        string(13) "Peter Cushing"
        ["order"]=>
        int(3)
        ["profile_path"]=>
        string(32) "/fg7ufC0IMr6VasQzzdmTtX5ycQF.jpg"
      }
      [4]=>
      array(7) {
        ["cast_id"]=>
        int(14)
        ["character"]=>
        string(20) "Obi-Wan "Ben" Kenobi"
        ["credit_id"]=>
        string(24) "52fe420dc3a36847f8000477"
        ["id"]=>
        int(12248)
        ["name"]=>
        string(13) "Alec Guinness"
        ["order"]=>
        int(4)
        ["profile_path"]=>
        string(32) "/89QNJ7u1hNaCglkotmZEbwCNp1M.jpg"
      }
      [5]=>
      array(7) {
        ["cast_id"]=>
        int(7)
        ["character"]=>
        string(20) "See Threepio (C-3PO)"
        ["credit_id"]=>
        string(24) "52fe420dc3a36847f8000451"
        ["id"]=>
        int(6)
        ["name"]=>
        string(15) "Anthony Daniels"
        ["order"]=>
        int(5)
        ["profile_path"]=>
        string(32) "/cljvryjb3VwTsNR7fjQKjNPMaBB.jpg"
      }
      [6]=>
      array(7) {
        ["cast_id"]=>
        int(8)
        ["character"]=>
        string(19) "Artoo-Detoo (R2-D2)"
        ["credit_id"]=>
        string(24) "52fe420dc3a36847f8000455"
        ["id"]=>
        int(130)
        ["name"]=>
        string(11) "Kenny Baker"
        ["order"]=>
        int(6)
        ["profile_path"]=>
        string(32) "/sdd9rgifNF9C51RejG7sUGU8Bka.jpg"
      }
      [7]=>
      array(7) {
        ["cast_id"]=>
        int(15)
        ["character"]=>
        string(9) "Chewbacca"
        ["credit_id"]=>
        string(24) "52fe420dc3a36847f800047b"
        ["id"]=>
        int(24343)
        ["name"]=>
        string(12) "Peter Mayhew"
        ["order"]=>
        int(7)
        ["profile_path"]=>
        string(32) "/din1s5H4C4CfcnkHfEeRcdFlsVj.jpg"
      }
      [8]=>
      array(7) {
        ["cast_id"]=>
        int(16)
        ["character"]=>
        string(11) "Darth Vader"
        ["credit_id"]=>
        string(24) "52fe420dc3a36847f800047f"
        ["id"]=>
        int(24342)
        ["name"]=>
        string(12) "David Prowse"
        ["order"]=>
        int(8)
        ["profile_path"]=>
        string(32) "/cJtmBVrjYwawh2cCiAfZkEjPeqc.jpg"
      }
      [9]=>
      array(7) {
        ["cast_id"]=>
        int(17)
        ["character"]=>
        string(28) "Voice of Darth Vader (voice)"
        ["credit_id"]=>
        string(24) "52fe420dc3a36847f8000483"
        ["id"]=>
        int(15152)
        ["name"]=>
        string(16) "James Earl Jones"
        ["order"]=>
        int(9)
        ["profile_path"]=>
        string(32) "/2ZuBf3ip2RXhkiQqGUjbUzAf4Nx.jpg"
      }
      [10]=>
      array(7) {
        ["cast_id"]=>
        int(18)
        ["character"]=>
        string(10) "Uncle Owen"
        ["credit_id"]=>
        string(24) "52fe420dc3a36847f8000487"
        ["id"]=>
        int(33032)
        ["name"]=>
        string(10) "Phil Brown"
        ["order"]=>
        int(10)
        ["profile_path"]=>
        string(32) "/exkyN66HiZWJDmpcOza2hWoswOo.jpg"
      }
      [11]=>
      array(7) {
        ["cast_id"]=>
        int(19)
        ["character"]=>
        string(9) "Aunt Beru"
        ["credit_id"]=>
        string(24) "52fe420dc3a36847f800048b"
        ["id"]=>
        int(131625)
        ["name"]=>
        string(14) "Shelagh Fraser"
        ["order"]=>
        int(11)
        ["profile_path"]=>
        string(32) "/xNfiibBvknHztEnL0g7dcdrxOKq.jpg"
      }
      [12]=>
      array(7) {
        ["cast_id"]=>
        int(24)
        ["character"]=>
        string(10) "Chief Jawa"
        ["credit_id"]=>
        string(24) "52fe420dc3a36847f800049f"
        ["id"]=>
        int(132538)
        ["name"]=>
        string(11) "Jack Purvis"
        ["order"]=>
        int(12)
        ["profile_path"]=>
        string(32) "/tuFTY1jhlEgZm3vM80KdAEvHwNI.jpg"
      }
        int(1)
        ["job"]=>
        string(8) "Director"
        ["name"]=>
        string(12) "George Lucas"
        ["profile_path"]=>
        string(32) "/8qxin8urtFE0NqaZNFWOuV537bH.jpg"
      }
      [1]=>
      array(6) {
        ["credit_id"]=>
        string(24) "562e75309251414006009955"
        ["department"]=>
        string(7) "Writing"
        ["id"]=>
        int(1)
        ["job"]=>
        string(6) "Writer"
        ["name"]=>
        string(12) "George Lucas"
        ["profile_path"]=>
        string(32) "/8qxin8urtFE0NqaZNFWOuV537bH.jpg"
      }




因此,从上面开始,我希望能够在主数组中显示数据,然后对于附加数据,我希望它显示如下:

导演:乔治卢卡斯 演员:Carrie Fisher,Mark Hammill,Harrison Ford [还有7个]

我很想获取API数据。所以对此的任何帮助都将非常感激。

0 个答案:

没有答案