score:1

In my opinion, from a logical perspective, I would use per row the output you have on this moment: dd-mm;data,data,... Is it logical to have the times on the X-axis? This would also mean you can use the append modus.

If you really want to keep the desired output then I would create an array per row something like:

$arr[0][] = '21:00';
$arr[1][] = 'data_b';
$arr[0][] = 'data_b';

$new_data = '';
foreach($arr as $row)
{
   $new_data .= implode(',', $row);
}

Note that you cannot use the append modus in this last situation that easily and that this might result in the need to retrieve more data from the database...

score:1

print_r($this->newCsvData) shoud be look like this:

$data = array(
    array( '21:00' ),
    array( '12' ),
    array( '40' ),
);

and in second step, shoud be look like this:

$data = array(
    array( '21:00', '21:01' ),
    array( '12', '15' ),
    array( '40', '40' ),
);

and third step, same:

so who you can do this. Each time you import all data from CSV file and push each cell to the corresponding array and look like this

$newArray = array(array(), array(), array());
foreach($dataFromCSV as $data)
{
   array_push($newArray[0][], $data[0]);
   array_push($newArray[1][], $data[1]);
   array_push($newArray[2][], $data[2]);
}

and then append the new record data in $newArray. delete the old data from CSV file and write on it with new data from $newArray.

:) enjoy


Related Query

More Query from same tag