title: Get Specific Attributes of all Array Keys in PHP Foreach Loop
body: <p>I'm working with a multi-dimensional PHP array that is converted from an XML file, and am struggling to grab specific attributes from all key names (I don't know the name of all keys, but they all have the same attributes.)</p>
  
  <p>Each Key inside "$player_stats" is structured like this in the array:</p>
  
  <pre><code>[RandomKeyName] =&gt; SimpleXMLElement Object
      (
          [@attributes] =&gt; Array
              (
                  [assists] =&gt; 0.10
                  [rebounds] =&gt; 8
                  [operator] =&gt; &gt;
                  [overall] =&gt; 1.45
              )
  
      )
  </code></pre>
  
  <p>I'm trying to achieve something like below. Am I not able to grab attributes from keys when using $key => $value?</p>
  
  <pre><code>foreach ($player_stats as $key =&gt; $value) {
  
      $rebounds = $key-&gt;rebounds;
      $assists = $key-&gt;assists;
  
      echo "$key has $rebounds Rebounds and $assists Assists. &lt;br&gt;";
  }
  </code></pre>
  
  <p>$key works in this example but the attributes I tried grabbing don't. Any tips or pointers for grabbing specific attributes for all keys without knowing the key names would be great, thanks!</p>
  
  <p>edit:</p>
  
  <p>The part of the XML I'm trying to get key objects of:</p>
  
  <pre><code>&lt;Player_Stats&gt;
    &lt;RandomKeyName1 assists="0.04" rebounds="9" operator="&amp;gt;" overall="0.78" /&gt;
    &lt;RandomKeyName2 assists="0.04" rebounds="4" operator="&amp;gt;" overall="2.07" /&gt;
    &lt;RandomKeyName3 assists="0.04" rebounds="1" operator="&amp;gt;" overall="3.76" /&gt;
    &lt;RandomKeyName4 assists="0.04" rebounds="10" operator="&amp;gt;" overall="0.06" /&gt;
  &lt;/Player_Stats&gt;
  </code></pre>