Get user field category 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-&gt;networksMatrix as $key =&gt; $networkLink)
{
    $netArr[$networkLink-&gt;id]["fields"]["networktype"] = $networkLink-&gt;networktype;
    $netArr[$networkLink-&gt;id]["fields"]["networkUrl"] = $networkLink-&gt;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-&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;
}


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-&gt;networktype-&gt;ids()[0];
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!

Matt V says:


  I discovered that the following works:

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

  
  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-&gt;networktype-&gt;ids()[0];