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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:54:45+00:00 2026-06-11T17:54:45+00:00

I have a multi-dimensional array that I want to print statistics from for a

  • 0

I have a multi-dimensional array that I want to print statistics from for a website admin. My problem is that once I get the data into an array in the format I want it, I can’t figure out how to retrieve it. I have to know the key values in order to get it e.g. $uniqueBrowser["Firefox"]["14.0.1"]['times'];

I want to be able to say for example – Firefox 70%, IE 30% as a start (aggregate all version ‘times used’ for the browsers). I then want to drill down further to specific versions e.g. FF3.6 14%, FF14 51% etc. (simply printing out the times value associated with the version).

EDIT: My Question is, how do I retrieve my data in the way described above?
My head is fried and I’ve been on this for too long. Please someone put me out of my misery. If there is a better way to do this, please let me know also.

The code I have so far is below. This code is run in a for each loop which iterates through data returned by the database. The $browser and $version variables are set to the browser values and version values returned from the database at each iteration of the foreach loop.

if(in_array($browser, $uniqueBrowser)) {        
    if(in_array($version, $uniqueBrowser[$browser])) {
        $uniqueBrowser[$browser][$version]['times'] = $uniqueBrowser[$browser][$version]['times'] + 1;
    } else {            
        $uniqueBrowser[$browser]['version'] = $version;
        $uniqueBrowser[$browser][$version]['times'] = 1;
    }       
} else {
    $uniqueBrowser[] = $browser;
    $uniqueBrowser[$browser]['version'] = $version;
    $uniqueBrowser[$browser][$version]['times'] = 1;
}

When I run this code, it gives me this (via var_dump):

Browser data: array(4) {
  [0]=>
  string(7) "Firefox"
  ["Firefox"]=>
  array(3) {
    ["version"]=>
    string(6) "14.0.1"
    [15]=>
    array(1) {
      ["times"]=>
      int(2)
    }
    ["14.0.1"]=>
    array(1) {
      ["times"]=>
      int(15)
    }
  }
  [1]=>
  string(17) "Internet Explorer"
  ["Internet Explorer"]=>
  array(2) {
    ["version"]=>
    string(9) "8.0.0.253"
    ["8.0.0.253"]=>
    array(1) {
      ["times"]=>
      int(1)
    }
  }
}
  • 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-11T17:54:46+00:00Added an answer on June 11, 2026 at 5:54 pm

    I know JvdBerg has already given an answer like this, but I added my comment first. So I don’t feel like I’m copying him.

    As an example I’ve created the following table structure. Hopefully it’s like yours.

    +---------+------------------+------+-----+---------+----------------+
    | Field   | Type             | Null | Key | Default | Extra          |
    +---------+------------------+------+-----+---------+----------------+
    | id      | int(11) unsigned | NO   | PRI | NULL    | auto_increment |
    | browser | varchar(120)     | YES  |     | NULL    |                |
    | version | varchar(50)      | YES  |     | NULL    |                |
    +---------+------------------+------+-----+---------+----------------+
    

    Then I inserted the following rows, again, hopefully like yours.

    +----+---------+---------+
    | id | browser | version |
    +----+---------+---------+
    |  1 | Firefox | 3.6     |
    |  2 | Firefox | 4.1     |
    |  3 | Firefox | 3.6     |
    |  4 | Safari  | 5.1.7   |
    |  5 | Safari  | 6       |
    |  6 | Firefox | 14.0.1  |
    |  7 | IE      | 7       |
    |  8 | IE      | 8       |
    |  9 | IE      | 7       |
    | 10 | Firefox | 14.0.1  |
    | 11 | Opera   | 12.0.1  |
    | 12 | Safari  | 5.1.7   |
    +----+---------+---------+
    

    Then the following query produced these results.

    mysql> SELECT browser, version, COUNT(version) AS times FROM demo.browsers GROUP BY browser;
    +---------+---------+-------+
    | browser | version | times |
    +---------+---------+-------+
    | Firefox | 3.6     |     5 |
    | IE      | 7       |     3 |
    | Opera   | 12.0.1  |     1 |
    | Safari  | 5.1.7   |     3 |
    +---------+---------+-------+
    

    If you want it to be more precise you can use GROUP BY browser, version instead of just by the browser.

    mysql> SELECT browser, version, COUNT(version) AS times FROM demo.browsers GROUP BY browser, version;
    +---------+---------+-------+
    | browser | version | times |
    +---------+---------+-------+
    | Firefox | 14.0.1  |     2 |
    | Firefox | 3.6     |     2 |
    | Firefox | 4.1     |     1 |
    | IE      | 7       |     2 |
    | IE      | 8       |     1 |
    | Opera   | 12.0.1  |     1 |
    | Safari  | 5.1.7   |     2 |
    | Safari  | 6       |     1 |
    +---------+---------+-------+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an multi-dimensional array that I want to send to a PHP script
i have this multi dimentional array that i want to print into a table
I have a very specific problem here. I have a multi-dimensional array that I
I have a multi-dimensional array similar to the example below that I want to
I'm having a problem lately that's driving me crazy. I have a multi-dimensional array
I have the following multi-dimensional array that I want to sort. I want to
I have a multi-dimensional array, no problem. How do I interrogator one of the
I have a multi-dimensional array which contains ten thousands of data. A lot... The
I have data that I want to pull from a mySQL database and I
I have a multi-dimensional array that looks like this: The base array is indexed

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.