<?php // function CSV($string) // { // $csvLine = explode(',', $string); // if(!is_numeric($string)){ // array_unshift($string, var) // } // } function parseEmployees($filename) { $handle = fopen($filename, "r"); $fileContentsString = fread($handle, filesize($filename)); $arrayOfStrings = explode("\n", trim($fileContentsString)); foreach ($arrayOfStrings as $info) { $personInfoArray = explode(",", $info); $employeeNumber = $personInfoArray[0]; $employeeFullName = $personInfoArray[1] . $personInfoArray[2]; $employeeSalesUnits = $personInfoArray[3]; $employees[] = array('units' => $employeeSalesUnits, 'name' => $employeeFullName, 'number' => $employeeNumber); } fclose($handle); return $employees; } var_dump(parseEmployees('report.txt'));
return "{$a}|{$b}|{$c}"; } function cleanString($total_length, $string) { $string_length = strlen($string); $spaces = $total_length - $string_length - 2; $string = " {$string}"; for ($i = 0; $i < $spaces / 2; $i++) { $string = " {$string} "; } if ($spaces % 2 === 0) { $string .= ' '; } return $string; } $employee = parseEmployees("data/report.txt"); //Saving the count of the employees into a variable called $data $data = count($employee); //Saving the function call to a variable called $unit $unit = unitTotal($employee); echo PHP_EOL; echo "Total Number of Employees: " . $data . PHP_EOL; echo "Total Number of Units Sold: " . $unit . PHP_EOL; echo "Average Units Sold Per Employee: " . $unit / $data . PHP_EOL; echo PHP_EOL; //Sort the array by units from the highest to the lowest arsort($employee); echo ' Units | Full Name | Employee Number' . PHP_EOL; echo '===========================================================================' . PHP_EOL; foreach ($employee as $employeeString) { echo cleanOutputForEmployee($employeeString) . PHP_EOL;