Hello, I need help in getting the mean, mode, median, an total sum out of a cvs file with php, what php function would help attain these for a cvs file?? many thanks Manni
Did you mean CSV file? comma-separated values if so you can use fopen then explode function to parse the data if its from a .csv file.
Here is the example for using fopen to open the file and fgetcsv to pull the data. In this example the data is echoed out line by line. But, you could just as easily place it into a SQL database and then perform the analytics on it such as mean, mode, median and total sum. <?php $row = 1; if (($handle = fopen("test.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p>\n"; $row++; for ($c=0; $c < $num; $c++) { echo $data[$c] . "<br />\n"; } } fclose($handle); } ?>