I have a multidimensional array in which the first level keys needs to be the first line of data in .csv string.
The rows of indexed elements need to be transpose and converted into subsequent lines of csv text.
The output will be identical to a .csv file's contents, but I don't want a file to be created, just as a .csv string.
Sample data:
$data = [
'dates' => ['2010-01-02', '2011-02-03', '2011-02-04'],
'type1' => ['data1', 'data2', 'data3'],
'type2' => ['data4', 'data5', 'data6']
];
Desired output string:
dates,type1,type2
2010-01-02,data1,data4
2011-02-03,data2,data5
2011-02-04,data3,data6