<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>

CC BY-SA 3.0
2015-08-23T01:31:01.153Z
2015-08-23T01:31:01.153Z
Ben Parizek
<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>

CC BY-SA 3.0
2015-04-18T23:19:29.383Z
That's great, Matt! Would you mind adding that as an official answer rather than an update to the original question?
Brad Bell
CC BY-SA 3.0
2015-04-21T17:04:04.463Z
Not sure what you mean?
Matt V
CC BY-SA 3.0
2015-04-21T17:06:02.327Z
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.
Brad Bell
<plugin-development><categories><field>
Get user field category
# 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, Matt! 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 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];


---

