title: Facebook SDK and PHP Array
body: <p>I am working with the Facebook SDK and PHP. Everything is working fine, but I am having trouble with one part, which is storing a specific field value into a variable.</p>
  
  <p>Here is the code, which gets and prints the info.</p>
  
  <pre><code>if ($session){ //if we have the FB session
  
      $user_profile = (new FacebookRequest($session, 'GET', '/me/accounts?fields=id,name,access_token'))-&gt;execute()-&gt;getGraphObject(GraphUser::className());
      //do stuff below, save user info to database etc.
      echo "Session Set.";
  
      echo '&lt;pre&gt;';
      print_r($user_profile); //Or just print all user details
      $variable = print_r($user_profile, TRUE);
      echo '&lt;/pre&gt;';
  
      // How do I get the first 'id', 'name', and 'access_token'
      // How do I get the second 'id', 'name', and 'access_token'
  }
  </code></pre>
  
  <p>And here is what prints (I replaced the actual data with XXXX for obvious reasons):</p>
  
  <pre><code>Session Set.
  Facebook\GraphUser Object
  (
      [backingData:protected] =&gt; Array
          (
              [data] =&gt; Array
                  (
                      [0] =&gt; stdClass Object
                          (
                              [id] =&gt; XXXXXXXX
                              [name] =&gt; XXXXXXXX
                              [access_token] =&gt; XXXXXXXXX
                          )
  
                      [1] =&gt; stdClass Object
                          (
                              [id] =&gt; XXXXXXXXX
                              [name] =&gt; XXXXXXXXX
                              [access_token] =&gt; XXXXXXXXX
                          )
  
                  )
  
              [paging] =&gt; stdClass Object
                  (
                      [cursors] =&gt; stdClass Object
                          (
                              [before] =&gt; XXXXXXX
                              [after] =&gt; XXXXXXX
                          )
  
                  )
  
          )
  
  )
  </code></pre>
  
  <p>How do I take [id], [name], and [access_token] and store them in variables so I can eventually save them into a db?</p>