我有 3 个数组,一个具有低值权重,另一个具有高值权重,第三个:该权重“括号”的实际值:
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
)
我需要从数组 3 中找到相应的 KEY,其中我的值(比如说 5.30)大于数组 1 中的值但小于数组 2 中的对应值(大于 5 但小于 20)。此示例的结果将从数组 3 生成数组键 [2] 和值 100。
我可以遍历每个数组并找到键,但我希望有一种更快的方法来做到这一点,通过某种方式合并数组:
[2] =>
[0] => 5.00
[1] => 20.00
[2] => 100
...然后查看我的值是否在 [0] 和 [1] 之间,如果是,则返回 [2] 基本上 [2][0] 是“从”重量,[2][1] 是“到”重量和该“括号”的值为 [2][2]。
使用示例代码合并数组:
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
)
)