I’ve got an old script from someone that I want to remodel but unfortunately I am not that experienced in PHP. What it does is, it reads article information from a CSV file into an array and then basically posts the output into a HTML table, which can then be saved into a PDF file.
One thing I couldn’t quite wrap my head around is, the file provides duplicate lines for an article while only some values changed (size, color etc). The article does have the same name but is not repeated twice in the output, the "new" values are just added to the already existing record and I am quite unsure how to do that. Let me give you a simplified example:
CSV Example:
ArtNo,Name,Color,Size
DEF270, Fingal, Stellar, 3XL
DEF270, Fingal, White, 4XL;
So, in a regular loop, the output would be like this
ArtNo | Name | Color | Size |
---|---|---|---|
DEF270 | Fingal | Stellar | 3XL |
DEF270 | Fingal | White | 4XL |
What I would need is this
ArtNo | Name | Color | Size |
---|---|---|---|
DEF270 | Fingal | Stellar, White | 3XL, 4XL |
Can you guys give me a hint on how to achieve this?
2
Answers
Let you loaded data from CSV to plain array. After this you can apply
array_reduce
in next way:PHPize – run php code online
You can process the whole file by grouping the article number and add the properties to each an array. On output you implode them comma delimited.
Output