K
K
krysestar2021-03-18 21:45:09
MODX
krysestar, 2021-03-18 21:45:09

How to iterate over an array using Fenom?

Topic on MODX template engine Fenom (a solution related to smart is also suitable, I think the approach is the same)

Greetings!

Actually the question is the following.
There is such an array, for example, which, with the help of processing, produces this:

id: 1 - count: 2
id: 2 - count: 1
id: 2 - count: 7

Actually, each line is a new element of the array. I scatter with the help of a phenom:
{var $array_test = 'm_dish' | placeholder}

{foreach $array_test as $row}
    id: {$row.id} - count: {$row.count}
{/foreach}

The question is next. Is it possible to somehow sort through the array using Phenom so that all array elements that have the same ID add up the second COUNT field and remove duplicate entries in the ID field

. should come out of this:
id: 1 - count: 2
id: 2 - count: 1
id: 2 - count: 7

This is:
id: 1 - count: 2
id: 2 - count: 8

Thank you in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arthur Sh, 2021-03-23
@Shev_Art_V

It's easier to write a snippet that will iterate over the original array and return the desired one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question