I'm working on a little project of mine, which involves an API from a video game, and I want to get stats from players from certain matches. The XML file from a certain match looks like this:
<result>
<players>
<player>
<name>NAME1</name>
<position>POSITION1</position>
<age>AGE1</age>
</player>
<player>
<name>NAME2</name>
<position>POSITION2</position>
<age>AGE2</age>
</player>
<player>
<name>NAME3</name>
<position>POSITION3</position>
<age>AGE3</age>
</player>
</players>
<winning_team>TEAM1</winning_team>
<duration>DURATION</duration>
</result>
Now, I want to run through every player and see if that players name is i.e. 'Chris', how do I go about doing this? I thought about doing something like this:
foreach($match_info->result->players->player as $player)
{
if($player->name == 'Chris')
echo 'I found Chris';
}
For more information, I'm using SimpleXMLElement to get the data from the XML file, and this works fine getting the winning_team and the duration, but I can't seem to figure out how to the get to the player names and then compare them all.
No comments:
Post a Comment