I have the following and would like to get some help in it:
function Display($line) {
$section = split(" +", $line);
for ($i = 1; $i <4; $i+=1){
$section[$i];
}
$countsection = count($section[3]);
$name = "$section[1] $section[2]";
print "<td>$name</td>\n";
print "<td>$countsection</td>\n";
$endvalue = end($section);
print "$endvalue";
}
$allvalues = file("filename.txt");
foreach ($allvalues as $checkline) {
if (ereg("^[[:digit:]]", $checkline)) {
Display($checkline);
}
}
Here’s a basic rundown:
I want
$counsectionand$endvalueto be counted. So the values inside$countsectionneed to be added together, the same for$endvalue.- $name needs to be merged together if they’re the same $name.
So the following would look something like this:
Name | Count Section | End Value
Mary Jane | 40 | 156
Tom John | 30 | 60
Instead of this:
Name | Count Section | End Value
Mary Jane | 10 | 50
Mary Jane | 10 | 50
Mary Jane | 20 | 56
Tom John | 10 | 20
Tom John | 15 | 30
Tom John | 5 | 10
File Content Sample:
12345 RM 100M 121 T 0400 1059 MWHA 110 Jane, Mary G 40
12345 RM 100M 122 W 0600 1059 MWHA 310 Jane, Mary P 40
12345 RM 100P 110 M W 0800 0929 CLOU 122 John, Tom 39
12345 RM 100P 210 M W 0930 1059 CLOU 205 John, Tom 40
Thanks in advance.
You can try
Output
Example
Function Used