mardi 16 février 2021

Grouping items from an array in TWIG/PHP

I have a TWIG/PHP array that is similar to the following:

Item [ Item Name, Item Ref Number, Item Quantity, Item Amount ]

I can have multiple lines in an Item so for example:

Item [
Item 1, 0001ABC, 1, 100
Item 2, 0002ADD, 1, 200
Item 3, 0001ABC, 1, 200
Item 4, 0002BDS, 3, 100
]

When the Ref Number matches, in this example Item 1 and 3, how can I group and show only these two instances and keep the other Items separate so that the output would show something similar to this:

Layout 1 (only when there are grouped items)
.---------------------------------.
Item 1, 0001ABC, 1, 100
Item 3, 0001ABC, 1, 200
.---------------------------------.

Layout 2 (Only when there are individual items)
.---------------------------------.
Item 2, 0002ADD, 1, 200
.---------------------------------.
Item 4, 0002BDS, 3, 100
.---------------------------------.

Aucun commentaire:

Enregistrer un commentaire