这是我的多个数组
Array
(
[3432] => Array
(
[2] => 7.2
[3] => 1.5
[4] => 2.1
)
[11350] => Array
(
[2] => 23.168
[3] => 4.344
[4] => 4.344
)
[12175] => Array
(
[2] => 8.112
[3] => 6.288
[4] => 4.344
)
[12306] => Array
(
[2] => 9.036
[3] => 0.9
[4] => 0
)
)
我需要找到一个最小值。 当我使用php min函数时,我得到10.8
Array
(
[2] => 7.2
[3] => 1.5
[4] => 2.1
)
10.8
但所有数组的最小值为9.936
[12306] => Array
(
[2] => 9.036
[3] => 0.9
[4] => 0
)
答案 0 :(得分:3)
试试这个:
<?php
$input = array(
11350 => array(
2 => 23.168,
3 => 4.344,
4 => 4.344,
),
12175 => array(
2 => 8.112,
3 => 6.288,
4 => 4.344,
),
12306 => array(
2 => 9.036,
3 => 0.9,
4 => 0,
),
);
$sums = array();
foreach ($input as $row) {
$sums[] = array_sum($row);
}
print_r(min($sums));
修改强>
或更多PHP方式:
print_r(min(array_map('array_sum', $input)));