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
)
)
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:
To do what you ask for (merge the arrays), you can use
array_map:And then: