fegtcsv does the work for fetching data of csv file in php
I wrote this code to fetch data from my input file
<?php
$file_handle = fopen("input.csv", "r");
while(!feof($file_handle)){
$line_of_text=fgetcsv($file_handle,3020);
$a= $line_of_text[1];
$b=$line_of_text[2];
$c=$line_of_text[3];
$d=$line_of_text[4];
}
fclose($file_handle);
?>
now what actually i want is to do is some matematical operation between third data ( which is $c ) in each line. for eg. add the $c in line 1 with $c of line 2. and some more mathematical operation. I will be able to do this only if I can get those data as c1, which would be $c of first line c2 which would be $c of second line. But I din’t find how to do that. the above script prints every line of the file. I have no control over which data of which line ( or row ) to print. how do I do that ? any thing I am missing to read or learn ? please let me know.
Every time you call
fgetcsvyou get another line. Therefore:Tip: you can also use loops within loops…