I need help converting this .csv file:
a;a1;1;0;1
b;b1;1;0;0
Into this output:
a;a1;1;
a;a1;0;
a;a1;1;
b;b1;1;
b;b1;0;
b;b1;0;
The output would then be inserted into a specific table in a database. (I have a script for that that works just fine.)
Logic on how it should work:
Count the number of columns (in this case from Column 3 to end of row. There has to be a var that describes from which column to count);
Count number of rows... Have a foreach loop to explode the data and set it as an array
$i=0
foreach($lines as $value) {
$data[$i] = explode(";", $value);
<...>
$i++;
}
count($data);
to get the number of rows
sizeof($data[0]);
get number of columns
Now due to my lack of php knowledge im kinda stuck here.
What you need to do is, for each line, array_splice
the 1st two elements, then loop through the remaining elements.
Something like this:
$data = array();
foreach($lines as $value) {
$value = explode(";", $value);
$first = array_splice($value, 0, 2);
foreach($value as $x){
$row = $first;
$row[] = $x;
$data[] = implode(';', $row);
}
}