I have a CSV file with thousands of numbers underneath each other. Let’s simplify by using this:
4
7
1
9
3
3
8
6
2
What I want is to output an array with 3 numbers per key (imploded by a comma):
array (
[0] => 4,7,1
[1] => 9,3,3
[2] => 8,6,2
)
I’ve managed to get to this, reading the CSV:
$path = "data.csv";
$row = 1;
if (($handle = fopen($path, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, "\r\n")) !== FALSE) {
$cell = 0;
$table[$row][$cell] = $data[0];
$cell++;
}
fclose($handle);
}
I am just confused as to where an how I have to up $row and $cell to get the output I want. Could you help?
Use this, I tested and works: