Sorry for the beginner question I'm still learning PHP.
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?
Here's is the segment of code where I'm trying to add in the foreach totals. far.
if (!empty($data['data'])) {
// Set vars
$products = array();
$output = '';
// Cart Values
$cartValues = $data['data'];
$output .= $modx->getChunk($cartTpl, $cartValues);
// Product Values
foreach($data['data']['products'] as $item) {
foreach($item as $key => $value) {
$products[$key] = $value;
}
$listProducts .= $modx->getChunk($productsTpl, $products);
$output = str_replace('[[+products]]', $listProducts, $output);
// Total Values
foreach($data['data']['totals'] as $total) {
foreach($total as $key => $value) {
$totals[$key] = $value;
}
$listTotals .= $modx->getChunk($totalsTpl, $totals);
$output = str_replace('[[+totals]]', $listTotals, $output);
}