Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8774849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:40:17+00:00 2026-06-13T18:40:17+00:00

I have the following and would like to get some help in it: function

  • 0

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

  • $counsection and $endvalue to be counted. So the values inside $countsection need 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:40:18+00:00Added an answer on June 13, 2026 at 6:40 pm

    You can try

    $allvalues = getValues("log.txt");
    print("<table>");
    foreach ( $allvalues as $name => $value ) {
        print("</tr>");
        printf("<td>%s</td><td>%d</td><td>%d</td>", $name, $value[0], $value[1]);
        print("</tr>");
    }
    print("</table>");
    

    Output

    <table>
        <tr>
            <td>Jane, Mary G</td>
            <td>121</td>
            <td>40</td>
        </tr>
        <tr>
            <td>Jane, Mary P</td>
            <td>122</td>
            <td>40</td>
        </tr>
        <tr>
            <td>John, Tom</td>
            <td>320</td>
            <td>79</td>
        </tr>
    </table>
    

    Example

    Jane, Mary G        121         40
    Jane, Mary P        122         40
    John, Tom           320         79
    

    Function Used

    function getValues($file) {
        $lines = file($file);
        $values = array();
        foreach ( $lines as $line ) {
            $line = trim($line);
            if (empty($line))
                continue;
            $line = explode("  ", $line);
            if (isset($values[$line[11]])) {
                $values[$line[11]][0] += strstr($line[3], " ");
                $values[$line[11]][1] += $line[13];
            } else {
                $values[$line[11]] = array(strstr($line[3], " "),$line[13]);
            }
        }
        return $values;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following line code in my view: <td> Model.some_instance_method(args) </td> I would like
I'd like some help with the following jQuery code if possible... $(document).ready(function() { $('table.sortable').each(function()
Say I have the following: [Test] // would like to parameterize the parameters in
i have the following problem: i would like to create a footer. that footer
I have the following table and would like to replace the string text of
Ok, I have the following problem: I would like to scroll an overflowing ListBox
I would like to have the following kind of HTML: <header></header> <div id='main'></div> <footer></footer>
I would like to have the following syntax: python utility.py file1 FILE1 file2 FILE2
I have the following actor for which I would like to create unit tests
I have the following collection which i would like to bind to a combobox:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.