I am using php-ml and taking in a .csv file with 6 columns and thousands of lines, i want every 5th element (column) of each array to be saved in $samples. I have tried the following which gives me the first element of each array.
$dataset = new CsvDataset('myCsvFile.csv', 1);
$samples = [];
foreach ($dataset->getSamples() as $sample) {
$samples[] = $sample[0];
}
However this gives me the first element of each array, if i change the $sample[0] to $sample[4]
as i thought syntactically this would work i get an Undefined offset on the line in question. I am new to PHP and don't understand why this would happen.
If the code is left as above and printed out it looks like the following:
Array
(
[0] => 1157
[1] => 1157
[2] => 1157
[3] => 1157
[4] => 1157
[5] => 1157
[6] => 1157
[7] => 1157
[8] => 1157
...and so on.