Undefined offset in php with json
<p>i was trying to use league of legends api and convert champion id to his name the code :</p>

<pre><code>  public function GetChampName($id)
  {
    $summObj = $this-&gt;getJSONObj('https://global.api.pvp.net/api/lol/static-data/na/v1.2/champion/' . $id .'?champData=image&amp;api_key=' . $this-&gt;apikey . '');
    $summID =  (string) ($summObj[$id]["key"]);

    return $summID;
   }
</code></pre>

<p>and use like that : </p>

<pre><code>                      $championid = $summoners[$i]['championId'];
                      $championName = $LolApi-&gt;GetChampName($championid);
</code></pre>

<p>$summoners is a array of participants in a current-game api.</p>

<p>when im doing </p>

<pre><code>var_dump($championName) 
</code></pre>

<p>im getting int(99) int(37) int(28) int(21) int(80) for example , and when im trying to use it like i said :</p>

<pre><code>                      $championid = $summoners[$i]['championId'];
                      $championName = $LolApi-&gt;GetChampName($championid);
</code></pre>

<p>Im getting this errors :</p>

<pre><code>Notice: Undefined offset: 99 in F:\xampp\htdocs\tilt\LolApi.php on line 24

Notice: Undefined offset: 37 in F:\xampp\htdocs\tilt\LolApi.php on line 24

Notice: Undefined offset: 28 in F:\xampp\htdocs\tilt\LolApi.php on line 24

Notice: Undefined offset: 21 in F:\xampp\htdocs\tilt\LolApi.php on line 24

Notice: Undefined offset: 80 in F:\xampp\htdocs\tilt\LolApi.php on line 24
</code></pre>

<p>line : </p>

<pre><code>$summID =  (string) ($summObj[$id]["key"]);
</code></pre>

<p>any idea how to fix it ? , i will provide anything needed to fix it.</p>