I have a CSV file with content similar to the following:
"Red",Red Coat
"",Red Dog
"",Red Car
"Blue",Blue Stuff
"Green",Green Stuff
"",Green Grass
I can read this and am output via PHP.
if (($handle = fopen("file.csv", "r")) !== FALSE) {
$row=0;
$csv_row = array();
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$csv_row = $data;
$previous=$csv_row[0]
$colour=$csv_row[0]
if $colouris null then $colour=$previous;
echo $colour." ".$csv_row[1]."<BR>";
}
fclose($handle);
}
And this will show me the Output with blanks for missing items.
Im not a Developer so forgive the question and ugly logic below. I want to use the existing value of $colour for the next $colour if its blank.
So something like:
$previous=$csv_row[0]
$colour=$csv_row[0]
if $colour is null then $colour=$previous;
So for my CSV would show me:
Red Red Coat
Red Red Dog ( previously Colour was empty)
Red Red Car ( previously Colour was empty)
Blue Blue Stuff
Green Green Stuff
Green Green Grass ( previously Colour was empty)
Any help appreciated!