Multiple foreach statements in PHP : <p>Sorry for the beginner question I'm still learning PHP.</p>

<p>I have a foreach statement which grabs some product data from an API which works as expected. I'm now trying to add in an additional foreach statement to grab the cart totals but when I add this in my text editor is throwing up a syntax error. No doubt I'm doing something wrong could anyone point me in the right direction please?</p>

<p>Here's is the segment of code where I'm trying to add in the foreach totals. far.</p>

<pre><code>     if (!empty($data['data'])) {

        // Set vars
        $products = array();
        $output = '';

        // Cart Values
        $cartValues = $data['data'];
        $output .= $modx-&gt;getChunk($cartTpl, $cartValues);

        // Product Values
        foreach($data['data']['products'] as $item) {
         foreach($item as $key =&gt; $value) {
            $products[$key] = $value;
        }

        $listProducts .= $modx-&gt;getChunk($productsTpl, $products);
        $output = str_replace('[[+products]]', $listProducts, $output);

        // Total Values
        foreach($data['data']['totals'] as $total) {
         foreach($total as $key =&gt; $value) {
            $totals[$key] = $value;
        }

        $listTotals .= $modx-&gt;getChunk($totalsTpl, $totals);
        $output = str_replace('[[+totals]]', $listTotals, $output);

    }
</code></pre>
