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

  • Home
  • SEARCH
  • 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 6918129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:49:10+00:00 2026-05-27T09:49:10+00:00

I’ve got an interesting problem with a few different ways to solve it. I’m

  • 0

I’ve got an interesting problem with a few different ways to solve it. I’m creating a reporting page for a small tool that takes the output from commands run on the command line and splits the aggregate info out into easier to read tables.

My code starts by running the cmd and filtering out some input. I’m running this in windows, so it’s using find instead of grep.

Here is an example of a few rows I might get back from the command, each row comes back as an element in an array:

Client client1 2011/06/16 root /appl/now 'area1: info'
Client client2 2011/06/16 root /appl/now 'area2: adds'
Client client3 2011/06/16 root /appl/now 'area3: text'
Client client4 2011/06/16 root /appl/now 'area4: text'
Client client5 2011/06/16 root /appl/now 'area3: text'
Client client6 2011/06/16 root /appl/now 'area3: adds'
Client client7 2011/06/16 root /appl/now 'area1: info'

What I need to do is take each row from the above output and group them based on the area<#> entry. Each unique string there (info, adds, etc) is a table, and every entry that has that value has another cmd run, and the output stored in the table. So for the above output I would have 4 tables; area1 would have 2 entries, area2 would have 1 entry, area3 would have 3 entries, and area4 would have 1 entry.

These values are stored in a database so I can do a select statement to get them, and then compare them against my original array, or loop through the array and store each unique value in another array. The first option seems faster when I have a very large dataset, and the second option seems faster when I have a small dataset. Which way is faster? Is there a better way that I haven’t thought of?

Now, to compare the array of all values against the array of unique values in order to group them into separate tables, what is the fastest way? I’m currently looping through, and if the value matches the unique value, I add that element to the table. This is done with nested foreach loops, which isn’t very efficient. Any suggestions?

  • 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-05-27T09:49:11+00:00Added an answer on May 27, 2026 at 9:49 am

    You should create an array of groups and iterate though your data set only once, as opposed to your nested loop design. It would look something like:

    <?php 
    foreach($dataset as $row):
        $groups[$row['area_key']][] = $row;
    endforeach; 
    ?>
    

    You would then create your tables from the $groups array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
i got an object with contents of html markup in it, for example: string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.