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 5994595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:50:24+00:00 2026-05-22T23:50:24+00:00

I have an multidimensional array of data which represents the list of users that

  • 0

I have an multidimensional array of data which represents the list of users that are connected to our servers. Each array contains information about a connection. The same user could be connected to any number of ports on different servers.

Array(  [0] => Array(
            [0] => serverA
            [1] => port1,
            [2] => user1,
            [3] => ip1
        ),
        [1] => Array(
            [0] => serverB
            [1] => port2,
            [2] => user2,
            [3] => ip2
            ),
        [2] => Array(
            [0] => serverC
            [1] => port1,
            [2] => user3,
            [3] => ip3
            ),  
        [3] => Array(
            [0] => serverA
            [1] => port1,
            [2] => user4,
            [3] => ip4
            ),  
        [4] => Array(
            [0] => serverB
            [1] => port4,
            [2] => user5,
            [3] => ip5
            ),  
        [5] => Array(
            [0] => serverC
            [1] => port1,
            [2] => user6,
            [3] => ip6
            ),
        [6] => Array(
            [0] => serverA
            [1] => port2,
            [2] => user7,
            [3] => ip7
            ),              
)

I need to group by first the servers and then the ports and print out a list showing the connected users for each server and port as below:

ServerA
    port1
        user1,ip1
        user4,ip4
    port2
        user7,ip2
ServerB
    port2
        user2,ip2
    port4
        user5,ip5
ServerC
    port1
        user3,ip3
        user6,ip6

I’m confused as to how to approach this. Should I be using a multidimensional array sort function (e.g. array_multisort) or should I be building a new array? An examples would be greatly appreciated.

  • 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-22T23:50:25+00:00Added an answer on May 22, 2026 at 11:50 pm

    You can create a new array where you summarize the data and then print it in the required format:

    $newArr = array();
    
    foreach($arr as $k => $v) {
            if(!isset($newArr[$v[0]][$v[1]])) {
                    $newArr[$v[0]][$v[1]] = array();
            }
            $newArr[$v[0]][$v[1]][] = array($v[2],$v[3]);
    }
    
    foreach($newArr as $k => $v) {
            echo $k,"\n";
            foreach($v as $k1 => $v1) {
                    echo "\t$k1\n";
                    foreach($v1 as $k2 => $v2) {
                            echo "\t\t", $v2[0],",",$v2[1],"\n";
                    }
            }
    
            echo "\n";
    }
    

    See it

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

Sidebar

Related Questions

I have CSV data loaded into a multidimensional array. In this way each row
I have been developing some code that uses Data.Array to use multidimensional arrays, now
I have an multidimensional array that looks like this: Array ( [0] => Array
Explanation I have a multidimensional array that is iterated over to created a categorized
I have just noticed that a multidimensional array in C# does not implement IEnumerable<T>
I have a PHP class that stores a complex multidimensional array, and rather than
how do I make a pointer to a multidimensional array, which have a unknown
I have a multi-dimensional array, which basically consists of one sub-array for each year.
I have a multidimensional array that looks something like this: ourThing = array( 'id'
Quick Question: I have the following array (multidimensional): Array ( [preorder] => 0 [data]

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.