dolejska-daniel / riot-api

Riot League of Legends & DataDragon API wrappers for PHP7 and PHP8.
GNU General Public License v3.0
112 stars 25 forks source link

How to get champion ID by Name ? #76

Closed elreco closed 4 years ago

elreco commented 4 years ago

Hello!

Is there a way to get a champion ID with a given name?

Thank you!

elreco commented 4 years ago

I found a solution,

$champions = DataDragonAPI::getStaticChampions();
foreach($champions['data'] as $c){
    if(strcasecmp($c['name'], $champion) == 0){
     $champion = intval($c['key']);
  }
}
dolejska-daniel commented 4 years ago

Hello @elreco, I'm sorry for responding so late 😞 There are also dedicated functions in DataDragonAPI for finding champions by their keys/IDs (not their actual names, e.g.: Annie, Wukong, …, you have solved that correctly):

Then you can easily access all their attributes - name, key, id, …