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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:09:36+00:00 2026-05-30T17:09:36+00:00

So i have an array, it has 1000 rows, and a column contains the

  • 0

So i have an array, it has 1000 rows, and a column contains the age of a user, im trying to determine how to count the amount of rows for people who are <17, 17-25, 26-40 etc.

I know this is possible with a for loop:

for($i=0,$i<$totalrows,$i++)
    $birthdate=$array[$i][birthdate];
    if($birthdate>1995)
    {
        $seventeen=$seventeen+1;
    }
    elseif
    {
        etc...

but is there a built in function that can do this instead of needing to do a for loop to calculate all the values? Once the count got to millions wouldn’t this become quite taxing on the server?

edit/ should i be doing this with like 5 different SQL Selects? just using a count(*)? would that be more efficient?

  • 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-30T17:09:37+00:00Added an answer on May 30, 2026 at 5:09 pm

    You could use array_filter() and then count() the return values from that.

    $seventeen = count(array_filter($array,
                                    function ($entry) { 
                                        return ($entry['birthdate'] > 1995); 
                                    }
                                   )
                      )
    

    N.B. Unless you have defined “birthdate” as a constant, you should quote it so that’s it’s treated as a string

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

Sidebar

Related Questions

I have an int array which has no elements and I'm trying to check
I have both matrices containing only ones and each array has 500 rows and
Ok, So I have a 2-d array of data which has the shape(23025, 1000),
In my code, I have an array that has about 1000 elements : Object[]
I have an array that has keys and values. For eg: Array ( [name]
I have an array which has the contents as the result of an sql
I have an array that has 22 items in it (it may also have
Lets say I have an array which has n dimensions. Now in order to
I have an array Items which has 10 elements. I need to remove the
I have a php array that has a bunch of data that I need

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.