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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:00:38+00:00 2026-06-15T11:00:38+00:00

I am fetching some data from the db and then push them to an

  • 0

I am fetching some data from the db and then push them to an array. I need to find the count of some strings and print out the result (count) in an efficient way:

Array
(
    [0] => q1-1,q2-2,q3-2,q4-1,q5-2,q6-3,q7-1,q8-4,
    [1] => q1-1,q2-2,q3-1,q4-3,q5-3,q6-3,q7-2,q8-1,
    [2] => q1-1,q2-1,q3-1,q4-1,q5-1,q6-2,q7-2,q8-2,
    [3] => q1-3,q2-1,q3-1,q4-1,q5-2,q6-3,q7-1,q8-1,
    [4] => q1-2,q2-2,q3-3,q4-1,q5-3,q6-3,q7-1,q8-1,
    [5] => q1-1,q2-2,q3-3,q4-1,q5-2,q6-3,q7-1,q8-1,
    [6] => q1-3,q2-1,q3-1,q4-3,q5-2,q6-3,q7-2,q8-4,
    [7] => q1-2,q2-2,q3-3,q4-1,q5-2,q6-5,q7-1,q8-1,
    [8] => q1-1,q2-1,q3-2,q4-3,q5-3,q6-5,q7-1,q8-1,
    [9] => q1-2,q2-1,q3-1,q4-1,q5-3,q6-3,q7-1,q8-1,
    [10] => q1-3,q2-2,q3-3,q4-3,q5-4,q6-3,q7-1,q8-1,
    ...
)

Sample data is above.

I need to know how many occurences of q1-1, q1-2 … q8-4 is in the array and print out readable version. Ex. The are 23: q1-1, 412: q1-2 and so on.

I was going to create an array of each string that needs to be searched that iterate through the array. For every result increment the resultVariable for that string but I’m not sure if that’s the best way.

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-06-15T11:00:41+00:00Added an answer on June 15, 2026 at 11:00 am

    Pretty simple, loop on your array, create sub arrays, and create a counter array:

    $counts = array () ;
    foreach ( $your_array as $row ) {
        $sub = explode(',', $row);
        foreach ( $sub as $subval ) {
            if ( array_key_exists ( $subval, $counts ) ) {
                $counts[$subval] ++ ;
            } else {
                $counts[$subval] = 1 ;
            }
        }
    }
    

    Here is $counts:

    Array (
        'q1-1' => 23,
        'q1-2' => 9,
        // and so on....
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having one array where i am fetching data from database for some
I am fetching some data from MySQL which I print into a table. I
I am fetching some data from a site using its API-key and some other
I'm fetching some data from an MSSQL table using the mssql_fetch_object, but the text
I am fetching some data having UTF8 collation ( utf8_unicode_ci ) from a MySQL
I am fetching data from some tables & storing it in a variable like
I am fetching some values in a forEach clause data.forEach(function(content){ ... controller.setAttribute(value from data);
I'm getting some weird thing happening with my javascript. I'm fetching data from the
I am fetching some data from php and trying to show that data in
hi everyone i am fetching some data from a database using php, encoding it

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.