Thanks again Chad
its starting to make sense. it seems to be a simple and therefore clever way of summing the info.
but could i bug you again please?
(i have modied the text file alittle by adding a first name to each record)
i can manipulate the array to calc the total hours worked by each employee and the total weeks worked; i do this by creating two separate arrays.
My problem now is that i want to calc the average per employee but i cannot figure out a way to join the two arrays.
Essence of problem:
2 associative arrays
@$times[$fields[1].", ".$fields[0]] += $fields[2]; // holds total hours worked
@$weeks[$fields[1].", ".$fields[0]] += 1; // holds total weeks worked
i want to either join them into one array (does this mean setting up a multi-dimensional array) or be able to access the two different array elements simultaneously so as to calculate the average.
I have a sinking feeling that i have painted myself into a corner. Is there a way out?
thanks once again
daniel
<?
echo"<h1>Salary Records - view average hours records</h1>";
$file = file("./salrecords.txt"); // read the file into the $file array
$times=array(); //holds the total hours worked
$weeks=array(); //holds the total weeks worked
//setup the display table
echo "<table border=1>\n";
echo"<tr> <th bgcolor = \"#CCCCFF\">No.</td>
<th bgcolor = \"#CCCCFF\">Employee</td>
<th bgcolor = \"#CCCCFF\">Total Weeks Worked</td>
<tr>";
// calculate the total hours worked
foreach($file as $line){
$fields = explode(",", $line);
@$times[$fields[1].", ".$fields[0]] += $fields[2];//This is summing the hours into the times array
@$weeks[$fields[1].", ".$fields[0]] += 1;//This is counting the weeks worked into the weeks array
}
// output single array only
$count=0;
foreach($weeks as $employee =>$weeks){
$count++;
echo"<tr><td>$count</td><td>$employee:</td><td>$weeks</td>"."<br>";
}
echo "</table>";
?>