I have a working system on which I receive data from two CSV files. And save all the data in an array, and then compare some data available in both csv files. The system works well, but later I found out that some of the lines are not displayed in the array. I think that I am not using the correct code when reading the csv file. I want to change / improve the system. This is my code when reading or receiving data from a csv file.
$thedata = array(); $data = file("upload/payment.csv"); foreach ($data as $deposit){ $depositarray = explode(",", $deposit); $depositlist = $depositarray; $key = md5($depositlist[9] . $depositlist[10]); $thedata[$key]['payment'] = array( 'name' => $depositlist[0], 'email' => $depositlist[1], 'modeofpayment' =>$depositlist[8], 'depositdate' => $depositlist[9], 'depositamount' => number_format($depositlist[10],2) ); } '<pre>',print_r($thedata),'</pre>';
1.) What is wrong with file("upload/payment.csv") when reading a csv file?
2.) What is the best code when reading a csv file that is applicable to the system without changing the whole code. A foreach loop should remain.
3.) Is fgetcsv much better for existing code? What changes should be made?
source share