<p>If you use:</p>

<pre><code>$partnerProducts = $currentPartner['0']-&gt;productInfo;
</code></pre>

<p>Then you should be able to do:</p>

<pre><code>foreach ($partnerProducts as $pp)
{
    echo ($pp['sku']);
}
</code></pre>

CC BY-SA 3.0
2015-07-23T22:42:45.917Z
So getContent() only returns the straight column values while the direct reference returns an array with the column values AND the table titles?
David Rampersad
CC BY-SA 3.0
2015-07-15T02:22:49.877Z
2015-07-15T02:22:49.877Z
Brad Bell
<p>When you set up a table field column through the admin cp, you assign a name and a handle. When I var_dump the table field, all row data is referenced by column number. (e.g. col1, col5, col2, col3, col4)</p>

<pre><code>    $partnerProducts = $currentPartner['0']-&gt;getContent()-&gt;productInfo;
    foreach ($partnerProducts as $pp){ echo ($pp['col2']); }
</code></pre>

<p>These columns may not be in order depending on how they were drag and dropped in the admin control panel, which is super confusing from the PHP plugin side. Is there any way to reference the table items by their cp handle?</p>

<p>You CAN do this from the twig side.</p>

<pre><code>    {% for partnerProduct in partner.productInfo %}
        {{ partnerProduct.sku  }}
    {% endfor %}
</code></pre>

<p>I'm still not sure what the difference between <code>$currentPartner['0']-&gt;getContent()-&gt;productInfo;</code> and <code>$currentPartner['0']-&gt;productInfo</code> is but the latter works.</p>

<plugins><fieldtypes><table-field>
Interacting with table fields via plugin
# Interacting with table fields via plugin

(Asked by: username_0 on 2015-07-14)

When you set up a table field column through the admin cp, you assign a name and a handle. When I var_dump the table field, all row data is referenced by column number. (e.g. col1, col5, col2, col3, col4)
    $partnerProducts = $currentPartner['0']->getContent()->productInfo;
    foreach ($partnerProducts as $pp){ echo ($pp['col2']); }

These columns may not be in order depending on how they were drag and dropped in the admin control panel, which is super confusing from the PHP plugin side. Is there any way to reference the table items by their cp handle?
You CAN do this from the twig side.
    {% for partnerProduct in partner.productInfo %}
        {{ partnerProduct.sku  }}
    {% endfor %}

I'm still not sure what the difference between $currentPartner['0']->getContent()->productInfo; and $currentPartner['0']->productInfo is but the latter works.

**Tags:** plugins, fieldtypes, table-field

---

## 1 answers

### Answer by username_1 on 2015-07-15. Score: 1 | Accepted answer

If you use:
$partnerProducts = $currentPartner['0']->productInfo;

Then you should be able to do:
foreach ($partnerProducts as $pp)
{
    echo ($pp['sku']);
}

> **Comments:**
> **username_0**: So getContent() only returns the straight column values while the direct reference returns an array with the column values AND the table titles?  

---

