ARRAY: https://api.twitch.tv/kraken/search/games?q=League%20of%20Legends&type=suggest
Greetings! I am trying to get a value within an array. What i'm trying to go for is the large box art of a certain game. So how do I do this? Here is my attempt, but I am getting these errors.
Notice: Trying to get property of non-object in /???/test.php on line 4
Notice: Trying to get property of non-object in /???/test.php on line 4
Notice: Trying to get property of non-object in /???/test.php on line 4
<?php
$game = urlencode($_GET['game']); // This is "League of Legends" in the URL
$json_array = json_decode(file_get_contents('https://api.twitch.tv/kraken/search/games?q={$game}&type=suggest'), true);
echo "IMG: ". $json_array->games[0]->box->large; // line 4
trueas the 2nd arg tojson_decodewhich forces it to create an associative array instead of an object. You want something like$json_array['games'][0]['box']['large']. Or simply don't pass a 2nd arg$_GETvalues are always strings. I'd also say passing it throughurlencode()is safe enoughfile_get_contentsfunction, otherwise the$gamevariable is not going to be replaced.