我们在 PHP 中有类似下面的数组,并且想要在新数组中创建一个新数组,应该有唯一的键,并且应该添加来自同一键的值。
Array
(
[0] => Array
(
[58] => 32.00
)
)
Array
(
[0] => Array
(
[58] => 34.00
)
)
Array
(
[0] => Array
(
[57] => 26.00
)
)
Array
(
[0] => Array
(
[57] => 27.00
)
)
Array
(
[0] => Array
(
[56] => 16.00
)
)
Array
(
[0] => Array
(
[56] => 17.00
)
)
我们想在上述数组的帮助下创建新数组。应添加相同键的值。新数组的输出应如下所示。
Array
(
[58] => 66
[57] => 53
[56] => 33
)
代码如下
minmaxarray 的输出是
Array
(
[0] => Array
(
[min] => 35.00
[max] => 50.00
[price] => 26.00
)
[1] => Array
(
[min] => 50.00
[max] => 80.00
[price] => 29.00
)
[2] => Array
(
[min] => 80.00
[max] => 100.00
[price] => 32.00
)
[3] => Array
(
[min] => 100.00
[max] => 150.00
[price] => 34.00
)
[4] => Array
(
[min] => 150.00
[max] => 180.99
[price] => 36.00
)
)
$shippingPrice = array();
foreach ($minmaxarray as $key => $value) {
if($price > $value['min'] && $price < $value['max'])
{
if($value['price'])
{
$shippingPrice[][$smethodid] = $value['price'];
break;
}
}
}
echo '<pre>'; print_r ($shippingPrice);
谢谢
汪汪一只猫
繁花不似锦
ITMISS