title: How to store XML child nodes in PHP variables through a given parent ID?
body: <pre><code>&lt;account VGS0035=&quot;VGS0035&quot;&gt;
          &lt;realm&gt;Smolderweb&lt;/realm&gt;
          &lt;realmint&gt;smolderweb-us&lt;/realmint&gt;
          &lt;type&gt;PvP&lt;/type&gt;
          &lt;race&gt;Undead&lt;/race&gt;
          &lt;gender&gt;Male&lt;/gender&gt;
          &lt;class&gt;Mage&lt;/class&gt;
          &lt;faction&gt;Horde&lt;/faction&gt;
          &lt;level&gt;60&lt;/level&gt;
          &lt;description&gt;(60% mount, green/blue gear)&lt;/description&gt;
          &lt;price&gt;210&lt;/price&gt;
          &lt;stock&gt;1&lt;/stock&gt;
          &lt;id&gt;VGS0035&lt;/id&gt;
          &lt;screenshot&gt;https://vanilla.games/wp-content/uploads/2019/08/wow-classic-mage.jpg&lt;/screenshot&gt;
      &lt;/account&gt;
  
      &lt;account VGS0036=&quot;VGS0036&quot;&gt;
          &lt;realm&gt;Faerlina&lt;/realm&gt;
          &lt;realmint&gt;faerlina-us&lt;/realmint&gt;
          &lt;type&gt;PvP&lt;/type&gt;
          &lt;race&gt;Undead&lt;/race&gt;
          &lt;gender&gt;Male&lt;/gender&gt;
          &lt;class&gt;Mage&lt;/class&gt;
          &lt;faction&gt;Horde&lt;/faction&gt;
          &lt;level&gt;60&lt;/level&gt;
          &lt;description&gt;(100% mount, epic/blue gear, Tailoring 300, First Aid 225, MC+ONY+BWL attuned, 150 gold)&lt;/description&gt;
          &lt;price&gt;400&lt;/price&gt;
          &lt;stock&gt;1&lt;/stock&gt;
          &lt;id&gt;VGS0036&lt;/id&gt;
          &lt;screenshot&gt;https://i.imgur.com/cdeAdwe.jpg&lt;/screenshot&gt;
      &lt;/account&gt;
  
      &lt;account VGS0037=&quot;VGS0037&quot;&gt;
          &lt;realm&gt;Faerlina&lt;/realm&gt;
          &lt;realmint&gt;faerlina-us&lt;/realmint&gt;
          &lt;type&gt;PvP&lt;/type&gt;
          &lt;race&gt;Undead&lt;/race&gt;
          &lt;gender&gt;Male&lt;/gender&gt;
          &lt;class&gt;Mage&lt;/class&gt;
          &lt;faction&gt;Horde&lt;/faction&gt;
          &lt;level&gt;60&lt;/level&gt;
          &lt;description&gt;(60% mount, green/blue/epic gear, 100 gold)&lt;/description&gt;
          &lt;price&gt;250&lt;/price&gt;
          &lt;stock&gt;1&lt;/stock&gt;
          &lt;id&gt;VGS0037&lt;/id&gt;
          &lt;screenshot&gt;https://vanilla.games/wp-content/uploads/2019/08/wow-classic-mage.jpg&lt;/screenshot&gt;
      &lt;/account&gt;
  </code></pre>
  <p>I have the following wrapped in XML tags. I have a PHP page where i pass a variable page?id=VGS0003 - I want to extract all of that node's child elements in PHP variables for use.</p>
  <pre><code>Example: 
  
  $realm = $account-&gt;realm;
  $region = $account-region;
  $race = $account-&gt;race;
  </code></pre>
  <p>I've tried almost every method but nothing seems to be working. Foreach only returns the last node no matter if i place if statements within the loop.</p>
  <pre><code>                $accountID = $_GET['id'];
                  
  
                  $xmlurl = &quot;../config/classic/accounts.php&quot;;
                  include($xmlurl);
                  $packages = new SimpleXMLElement($xmlstr);
  
                  foreach($packages-&gt;accounts-&gt;account as $account){
  
                      if($accountID == $account-&gt;id){
  
                      $accountRace = $account-&gt;race;
                      $accountRaceLowerU = strtolower($accountRace);
                      $accountRaceLowerU = str_replace(' ', '_', $accountRaceLowerU);
                      $accountGender = $account-&gt;gender;
                      $accountGenderLower = strtolower($accountGender);
                      $accountClass = $account-&gt;class;
                      $accountClassLower = strtolower($accountClass);
                      $accountFaction = $account-&gt;faction;
                      $accountScreenshotThumb = $account-&gt;images-&gt;image[0];
                      $accountScreenshot = $account-&gt;screenshot;
                      $accountSKU = $account-&gt;id;
                      $accountLevel = $account-&gt;level;
                      $accountRealm = $account-&gt;realm;
                      $accountType = $account-&gt;type;
  
                      }
  
                  };
  </code></pre>
  <p>How to accomplish this? What I am looking to do is rather simple, yet it seems i've tried everything. Find the account node through the ID, and save the child element values as php variables to be used elsewhere on the page.</p>