Search code examples
phpthemoviedb-api

TMDB PHP result array


I use code in PHP for get info about season. How I can get result in array?? Thanks.

Doc TMDB

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.themoviedb.org/3/tv/xxx/season/xxx?language=en-US&api_key=xxx",

$response = curl_exec($curl);
 echo $response;

Solution

  • Your expected result seems to be a JSON-object, according to the documentation you linked - so echo won't work. Use var_dump(json_decode($response)); to see the result.

    If you want to work with the JSON-object in PHP you will have to "cast" it to a PHP-object:

    $newObject = json_decode($response);
    

    You can than access the objects properties in PHP like so:

    echo $newObject->id;
    echo $newObject->name;
    

    etc.. See the PHP documentation on this topic here: PHP - json-decode