Hi I am very new to using API's with PHP. This is my first attempt. So far I have got the data being returned in a JSON format. I have the json_decoded()
it and the var_dump()
is returning what I can only work out as an object within an object. My PHP inexperience might be showing here.
Below is the code I am using which is successfully retrieving data.
$url = 'https://euw.api.pvp.net/api/lol/euw/v1.4/summoner/by-name/elderofaegis?api_key=RemovedForSO';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_URL, $url);
$output = curl_exec($ch);
curl_close($ch);
$result = json_decode($output);
var_dump($result);
Below is what the var_dump()
is returning
object(stdClass)[1]
public 'elderofaegis' =>
object(stdClass)[2]
public 'id' => int 38186794
public 'name' => string 'ElderOfAegis' (length=12)
public 'profileIconId' => int 785
public 'summonerLevel' => int 30
public 'revisionDate' => float 1427933098000
Does anyone know how I could access the object by its name. By this i mean the sections contained within the quotes for example if i want to echo the name i want something along the lines of (Pseudo Below).
echo $result->object['name'];
The above example is Pseudo Because I can't figure it out. For anyone wondering this is the League Of Legends API
Thanks.