I am learning php as part of my studies and at the moment I want to read a csv file into an array and then count all the values. I have successfully read the file and can display all the values in the csv file but am unable to sum/ add them in order to find a total.
Here is my code so far:
<?php
$data= explode(",",
file_get_contents('https://www.mywebsite.com/test.csv')
);
$total = 0;
$lengthofarray=count($data);
for($x=0;$x<=$lengthofarray;$x++)
{
$total = $total + $x;
//I am not sure if I am missing something here in order to make it working
}
echo " ".$total."<br/>";
?>
I know that this is a basic question but I have spent more than 12 hours in order to achieve the solution and have search internet to find the solution but unable to do so.
Here are the values from my csv file:
0.78
0.19
0.78
0.98
0.65
0.79
0.34
0.29
0.55
0.95