<?php $n = array( '0' => '1.1-4.6', '1' => '1.2-33.7', '2' => '1.3', '3' => '1.4-30', '4' => '15-44', '5' => '1.1-4.6', '6' => '1.2-33.7', '7' => '1.3', '8' => '1.4-43.9', '9' => '9.5-44', ); $nn = check_zifu($n); for ($ii=0; $ii 1) { //判断是否是范围,若不是,左边界值和右边界值相同 $nnn[$ii]['min'] = ceil($nn[$ii][0]); $nnn[$ii]['max'] = floor($nn[$ii][1]); }else{ $nnn[$ii]['min'] = $nn[$ii][0]; $nnn[$ii]['max'] = $nn[$ii][0]; } } $nnnn = getNum($nnn); echo "<pre class="brush:php;toolbar:false">"; print_r($nnnn); function check_zifu($a){ $c = array(); for ($i=0; $i 100){ //若左边界值和大于100或右边界值和小于100,不成立 for ($iii=0; $iii 100) { $c['min'][$iii] = $c['min'][$iii] - (array_sum($c['min']) - 100); return $c['min']; break; } } } }else if($min_sum == 100){ //若左边界值和为100 for ($ii=0; $ii
以上就介绍了 php在范围中取值并使和为100,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。