I'm developing an app using PHP and I'm fetching data via api endpoint. I was able to get the data I want - a huge chunk of it, found here: https://gist.github.com/kamaelxiii/18ef0c1600330b98717b96db00532d6a
Now my blocker is I just want to get and store the specific ID of a player (look for name : kamaelxiii) my code was able to get the ID but the page also displays this message:
Notice: Undefined index: name in C:\xampp\htdocs\vgapp\index.php on line 230
I'm thinking that this is because I'm looping to the entire included
block but not all contains the index name
in it. I've tried adding break
inside the for loop below but the ID that I'm after is not always the first in the list so there are times that the message above still shows - most of the time.
Here's my line of code that gets the specific ID:
if(is_array($finaljson) || is_object($finaljson)){
foreach ($finaljson['included'] as $key => $value) {
if($value['attributes']['name'] === $username){
$userid = $value['id'];
}
}