-3

I Want to convert the string into an array and return the rating value. I've been able to return it as a string so its nothing wrong with the first line of code.

JSON:

{
    "id": "23",
    "rating": "31"
}

Code:

$json = file_get_contents('http:*****='.$film->id.'') ;
    $array = json_decode($json,TRUE);
    echo $array[1] ;
Tristan
  • 3,301
  • 8
  • 22
  • 27
hotkeying
  • 1
  • 2
  • Have you tried `echo $array['rating'];`? Use `print_r($array);` and you'll see that the key is `rating`, not `1`. – FirstOne Dec 31 '15 at 00:15

1 Answers1

1

Line 3 should be:

echo $array['rating'];
Eduardo Escobar
  • 3,301
  • 2
  • 18
  • 15