数据操作PHP [关闭]

I have a csv file with data I would like the data to be filled in the empty spaces. then export to excel file or into a database for example. I would like the first column to copy the first Product A to fill the other spaces

For example

Type       Description Cost
Product A   rrrrrrrr    33.00
NEEDS FILL  ttttttttt   45.00
NEEDS FILL  eeeeeeeee   50.00
Product B   yyyyyyyyy   80.00
NEEDS FILL   qqqqqqq    90.00
NEEDS FILL  iiiiiiii    100.00

Needs to look like this

Type       Description Cost
Product A   rrrrrrrr    33.00
Product A ttttttttt     45.00
Product A  eeeeeeeee    50.00
Product B   yyyyyyyyy   80.00
Product B   qqqqqqq     90.00
Product B  iiiiiiii     100.00

The file result will be written in a file please help been scratching my head

Seems like you have no code, so all I can give you is outlines:

You will need fgetcsv() to read the CSV file. You can start with the example code from the manual.

Loop through the lines, always saving column 1 into a variable, so you will still have it on the next iteration. If column 1 in the current iteration is empty, use the saved value.

fputcsv() can be used to create the new CSV file on the fly.