Answers.Body: <p>For the sake of completeness, the question was resolved by the asker and I will quote his answer here, so this fine question is recognized by Stack Exchange as answered!</p>
  
  <p>Matt V says:</p>
  
  <blockquote>
    <p>I discovered that the following works:</p>
  
  <pre><code>foreach ($user-&gt;networksMatrix as $key =&gt; $networkLink)
  {
      $netArr[$networkLink-&gt;id]["fields"]["networktype"] = $networkLink-&gt;networktype-&gt;ids()[0];
      $netArr[$networkLink-&gt;id]["fields"]["networkUrl"] = $networkLink-&gt;networkUrl;
  }
  </code></pre>
    
    <p>Since networktype is a categories field and that field is limited to 1
    category I'll only ever get a single result from the method:</p>
  
  <pre><code>ids();
  </code></pre>
    
    <p>So... I just do this and I'm good:</p>
  
  <pre><code>$networkLink-&gt;networktype-&gt;ids()[0];
  </code></pre>
  </blockquote>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-23T01:31:01.153Z
Answers.LastActivityDate: 2015-08-23T01:31:01.153Z
Answers.UserDisplayName: Ben Parizek
Body: <p>I have a matrix that contains a block with a category field. I want to loop over the matrix models, <strong><em>in PHP</em></strong>, to get data. Here's what I have so far:</p>
  
  <pre><code>foreach ($user-&gt;networksMatrix as $key =&gt; $networkLink)
  {
      $netArr[$networkLink-&gt;id]["fields"]["networktype"] = $networkLink-&gt;networktype;
      $netArr[$networkLink-&gt;id]["fields"]["networkUrl"] = $networkLink-&gt;networkUrl;
  }
  </code></pre>
  
  <p><strong>networktype</strong> is a category field. How do I get the get the ID of the category a user selected?</p>
  
  <p>Thanks!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I discovered that the following works: </p>
  
  <pre><code>foreach ($user-&gt;networksMatrix as $key =&gt; $networkLink)
  {
      $netArr[$networkLink-&gt;id]["fields"]["networktype"] = $networkLink-&gt;networktype-&gt;ids()[0];
      $netArr[$networkLink-&gt;id]["fields"]["networkUrl"] = $networkLink-&gt;networkUrl;
  }
  </code></pre>
  
  <p>Since <strong>networktype</strong> is a categories field and that field is limited to 1 category I'll only ever get a single result from the method:</p>
  
  <pre><code>ids();
  </code></pre>
  
  <p>So... I just do this and I'm good:</p>
  
  <pre><code>$networkLink-&gt;networktype-&gt;ids()[0];
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-18T23:19:29.383Z
Comments.Text: That's great, Matt! Would you mind adding that as an official answer rather than an update to the original question?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-21T17:04:04.463Z
Comments.Text: Not sure what you mean?
Comments.UserDisplayName: Matt V
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-21T17:06:02.327Z
Comments.Text: The part where you updated your question with a solution.  Can you add that under the "Your Answer" portion on the bottom of the page?  That adds it as an official answer to the question.
Comments.UserDisplayName: Brad Bell
Tags: <plugin-development><categories><field>
Title: Get user field category
ThreadText: # Get user field category
  
  (Asked by: username_0 on 2015-04-18)
  
  I have a matrix that contains a block with a category field. I want to loop over the matrix models, ***in PHP***, to get data. Here's what I have so far:
  
  ```
  foreach ($user->networksMatrix as $key => $networkLink)
  {
      $netArr[$networkLink->id]["fields"]["networktype"] = $networkLink->networktype;
      $netArr[$networkLink->id]["fields"]["networkUrl"] = $networkLink->networkUrl;
  }
  
  ```
  
  **networktype** is a category field. How do I get the get the ID of the category a user selected?
  
  Thanks!
  
  **UPDATE**
  
  I discovered that the following works:
  
  ```
  foreach ($user->networksMatrix as $key => $networkLink)
  {
      $netArr[$networkLink->id]["fields"]["networktype"] = $networkLink->networktype->ids()[0];
      $netArr[$networkLink->id]["fields"]["networkUrl"] = $networkLink->networkUrl;
  }
  
  ```
  
  Since **networktype** is a categories field and that field is limited to 1 category I'll only ever get a single result from the method:
  
  ```
  ids();
  
  ```
  
  So... I just do this and I'm good:
  
  ```
  $networkLink->networktype->ids()[0];
  
  ```
  
  **Tags:** plugin-development, categories, field
  
  > **Comments:**
  > **username_1**: That's great, username_0! Would you mind adding that as an official answer rather than an update to the original question?  
  > **username_0**: Not sure what you mean?  
  > **username_1**: The part where you updated your question with a solution.  Can you add that under the "Your Answer" portion on the bottom of the page?  That adds it as an official answer to the question.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2015-08-23. Score: 4
  
  For the sake of completeness, the question was resolved by the asker and I will quote his answer here, so this fine question is recognized by Stack Exchange as answered!
  
  username_0 V says:
  
  > I discovered that the following works:
  >
  > ```
  > foreach ($user->networksMatrix as $key => $networkLink)
  > {
  >     $netArr[$networkLink->id]["fields"]["networktype"] = $networkLink->networktype->ids()[0];
  >     $netArr[$networkLink->id]["fields"]["networkUrl"] = $networkLink->networkUrl;
  > }
  >
  > ```
  >
  > Since networktype is a categories field and that field is limited to 1
  > category I'll only ever get a single result from the method:
  >
  > ```
  > ids();
  >
  > ```
  >
  > So... I just do this and I'm good:
  >
  > ```
  > $networkLink->networktype->ids()[0];
  >
  > ```
  
  
  ---
  
  