I can not get an Array

0

I'm trying to get a value inside an array, but it does not print anything from the id field, which is the field I want to get

$jsonc = file_get_contents("https://api.themoviedb.org/3/search/tv?query=todo%20o%20mundo%20odeia%20o%20chris&api_key=b5ad6a9f75ea4e476b5f08b524ddf83d");
$epjson = json_decode($jsonc);    
print_r($epjson -> id);

NOTE: When I do only print_r($epjson); it prints this:

  

stdClass Object ([page] = > 1 [total_results] = > 1 [total_pages] = > 1   [results] = > Array ([0] => stdClass Object ([original_name] = >   Everybody Hates Chris [id] = > 252 [name] = > Everybody Hates Chris   [vote_count] = > 68 [vote_average] = > 6.82 [poster_path] = >   /dM0IUKmrjyhFskt0ZBMbbfWxRIQ.jpg [first_air_date] = > 2005-09-22   [popularity] = > 10.150596 [genre_ids] = > Array ([0] = > 35)   [original_language] = > in [backdrop_path] = >   /xYLcbJoQEowXFVqe94A37CIC0Tq.jpg [overview] = > Everybody Hates Chris   is an American television narrative sitcom that depicts the troubled   teenage experiences of comedian Chris Rock while growing up in   Bedford-Stuyvesant, Brooklyn, New York City. The show is set between   1982 and 1987, but Rock himself was a teenager between 1978 and 1983.   Kenny Montero, whom he has often   referred to as the inspiration for a lot of the episodes. In many of   his interviews, Rock has described Kenny as the reason he got into   comedy in the first place. The show's title parodies the hit CBS   sitcom Everybody Loves Raymond, in which Rock stated: "Everybody Loves   Raymond, but Everybody Hates Chris! "The show's lead actors are Tyler   James Williams, Terry Crews, Tichina Arnold, Tequan Richmond, Imani   Hakim, and Vincent Martella. In 2008, The CW moved Everybody Hates   Chris and the Game to the Friday night death slot. The fourth season   of the series premiered Friday, October 3, 2008, at 8:00 PM   Eastern / 7: 00PM Central. On May 21, 2009, The CW announced that it had   canceled Everybody Hates Chris. Prior to this, Rock announced that   the end of season 4 matched up with his own past-dropping out of high   school to become a comedian-and that it was time to end the show.   [origin_country] = > Array ([0] = > US))))

    
asked by anonymous 22.11.2017 / 17:57

1 answer

1

Notice the structure of the information in the API you are using:

{
    "page": 1,
    "total_results": 1,
    "total_pages": 1,
    "results": [{
                "original_name": "Everybody Hates Chris",
                "id": 252,
                "name": "Everybody Hates Chris",
                "vote_count": 68,
                ....

The id is not right at the root but within the results array, so you should access it with:

print_r($epjson->results[0]->id);

If you have more than one result and you want the id of the various results, you must use for to scroll through them.

    
23.11.2017 / 00:09