Is there more efficient way of processing my XML file in PHP? The page is assigning $gid to the url paramater gid. It then reads an XML file that looks like this:

&lt;games&gt;
 &lt;game&gt;
  &lt;name&gt;name 1&lt;/name&gt;
  &lt;appID&gt;1234&lt;/appID&gt;
 &lt;/game&gt;
 &lt;game&gt;
  &lt;name&gt;name 2&lt;/name&gt;
  &lt;appID&gt;5678&lt;/appID&gt;
 &lt;/game&gt;
&lt;/games&gt;


The code I am using works correctly but takes a second to load because there are so many &lt;game&gt; 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-&gt;games;

foreach ($games-&gt;game as $game) {
  if ($gid == $game-&gt;appID) {
    $appid = $game-&gt;appID;
    $gamename = $game-&gt;name; 
  }
}

echo $gid, "&lt;br /&gt;";
echo $appid, "&lt;br /&gt;";
echo $gamename;
Add a break to that if statement to stop looping once you've found the correct node.