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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:44:06+00:00 2026-06-17T14:44:06+00:00

I need to find matching items in an array based on min and max

  • 0

I need to find matching items in an array based on min and max values in PHP. Short of an elaborate foreach,if,elseif,then clause, how can I efficiently get matching rows?

For example… Given array $arr (below), and the number 4, how can I return array rows 1,2, and 3?

$arr = array(
    0 => array( 'min' => 1,     'max' => 1,     'name' => 'alpha'),
    1 => array( 'min' => 1,     'max' => 9,     'name' => 'beta'),
    2 => array( 'min' => 1,     'max' => 19,    'name' => 'gamma'),
    3 => array( 'min' => 2,     'max' => 29,    'name' => 'delta'),
    4 => array( 'min' => 10,    'max' => 100,   'name' => 'epsilon'),
    5 => array( 'min' => 20,    'max' => 100,   'name' => 'zeta'),
    6 => array( 'min' => 30,    'max' => 100,   'name' => 'eta')
);

I’m hoping to turn this into a function. Something like this:

function findMatchingRows($n) {
    $arr = /*** see above ***/;
    /*** your answer! ***/
    return $matchingRows;
}

$n = 12;
print_r(findMatchingRows($n));

Expected result would be for above should be rows 2, 3, and 4. But I would expect it to work for any integer between 1 and 100.

  • 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-17T14:44:08+00:00Added an answer on June 17, 2026 at 2:44 pm
    $number = 4;
    $result = array_filter($arr, function ($elem) use ($number) {
       return $elem['min'] <= $number && $number <= $elem['max'];
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of items and I need to find the matching ones(duplicates).
I need to find the most efficient way of matching multiple regular expressions on
I have a PMS(Pantone Matching System) color value. I need to find the corresponding
I need to find a flexible solution for access control in PHP. In the
i need to find out automationid for key board values? how to send keystrokes
I need find a line matching a pattern like: A xx B xx, where
I need to find all records stored in postgres, which matching following regexp: ^((8|\+7)[\-
I need to find a reliable method to search for Arabic words using PHP.
I need to find the matching GUID in string using Regex string findGuid=hi sdkfj
I need to find some matching conditions from a file and recursively find the

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.