The page is assigning $gid
to the url paramater gid. It then reads an XML file that looks like this:
<games> <game> <name>name 1</name> <appID>1234</appID> </game> <game> <name>name 2</name> <appID>5678</appID> </game> </games>
The code I am using works correctly but takes a second to load because there are so many <game>
elements on the list. Is there are more efficient way to go about foreach? Here is the code:
$gid = (int) $_GET['gid']; $gamespage = simplexml_load_file("http://gamepage.com/games?xml=1"); $games = $gamespage->games; foreach ($games->game as $game) { if ($gid == $game->appID) { $appid = $game->appID; $gamename = $game->name; } } echo $gid, "<br />"; echo $appid, "<br />"; echo $gamename;
foreach
loop, but because you're fetching all of the data from a remote server every single time.\$\endgroup\$