I have a while loop that uses the fgetcsv function and iterates through a csv file until the end. In the loop I want to add a value from a specific column to a new array.
Everything works as it echos the value from the column that I need. However when I put the line in to add to the array it does not work. I have a HTML table that prints after the PHP code however when I use the line to add to the array it does not work.
I have looked on the internet and everything I have seen is doing it the way I have done so I am a little confused.
Here is my code:
$amountRecords = 0;
$totalValue = 0;
$valueArray = array();
$handle = fopen('data.csv', 'r');
// to skip the header names/values
fgetcsv($handle);
while($row = fgetcsv($handle, "\r"))
{
$valueArray[$amountRecords] += $row[1]; // THIS IS THE LINE THAT IS NOT WORKING
$totalValue = $totalValue + $row[1];
$amountRecords++;
}