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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:25:35+00:00 2026-06-06T00:25:35+00:00

I have 3 arrays, one has low value weight, the other high value weights,

  • 0

I have 3 arrays, one has low value weight, the other high value weights, the third: the actual value for that weight ‘bracket’:

Array 1
(
    [0] => 0.00
    [1] => 2.00
    [2] => 5.00
    [3] => 20.00
    [4] => 50.00
    [5] => 100.00
)
Array 2
(
    [0] => 1.90
    [1] => 4.90
    [2] => 20.00
    [3] => 50.00
    [4] => 100.00
)
Array 3
(
    [0] => 30
    [1] => 50
    [2] => 100
    [3] => 200
    [4] => 500
    [5] => 1000
)

I need to find the corresponding KEY from Array 3, where my value (lets say 5.30) is greater than a value in array 1 but less than its corresponding value in array 2 (greater than 5 but less than 20). The result of this example would produce the array key of [2] from Array 3 and the value of 100.

I could loop through each array and find the keys, but Im hoping there is a faster way to do this, by somehow merging the arrays:

    [2] =>  
        [0] => 5.00
        [1] => 20.00
        [2] => 100

…and then seeing if my value is between [0] and [1], if so return [2]
Basically [2][0] is ‘from’ weight, [2][1] is ‘to’ weight and the value for that ‘bracket’ is [2][2].

Merged Array using example code:

Array
(
    [0] => Array
        (
            [0] => 0.00
            [1] => 1.90
            [2] => 30
        )

    [1] => Array
        (
            [0] => 2.00
            [1] => 4.90
            [2] => 50
        )

    [2] => Array
        (
            [0] => 5.00
            [1] => 20.00
            [2] => 100
        )

    [3] => Array
        (
            [0] => 20.00
            [1] => 50.00
            [2] => 200
        )

    [4] => Array
        (
            [0] => 50.00
            [1] => 100.00
            [2] => 500
        )

    [5] => Array
        (
            [0] => 100.00
            [1] => 
            [2] => 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-06T00:25:36+00:00Added an answer on June 6, 2026 at 12:25 am

    It would be so much easier if your input data was not structured in such an unfortunate manner.

    Anyway, if you want to do this fast then the appropriate solution is probably manual looping:

    // possibly add some error checking
    foreach($lows as $i => $low) {
        if ($value >= $low && isset($highs[$i]) && $value <= $highs[$i]) {
            return $values[$i];
        }
    }
    

    To do what you ask for (merge the arrays), you can use array_map:

    $merged = array_map(
              function($low, $high = null, $value) {
                  return func_get_args();
              },
              $lows, $highs, $values);
    

    And then:

    foreach($bands as $band) {
        if($value >= $band[0] && $band[1] && $value <= $band[1]) {
            return $band[2];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two arrays the first one has this structure Parameter Keys array array
I have two arrays of data that I'm trying to amalgamate. One contains actual
I have two arrays. If an object in one array has no matching email
I have two arrays, one is a node-node-cost array [a_node,b_node,cost] which has 8000 entries
Say I have two arrays where one is a permutation of the other: A
I have some Javascript code that creates 2 arrays: One for Product Category and
I have two arrays, one is very large (more than million entries) and other
I have 2 arrays that I would like to render in a template, one
I have 2 arrays, I want to remove the one from the other. I
I have two different arrays. One array, a, for a list of people. My

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.