if(!function_exists('cutArraryLenth')) { /** * 截取数组的长度[饼图用] * @author lulijuan * @param type $data * @param type $length * @return string */ function cutArraryLenth($data, $key='key', $value='value',$length=5, $other = 0) { $count = count($data); $arr = []; $otherPrice = 0; if($count > $length) { $i = 0; foreach($data as $val) { if($i<$length) { $arr[] = $val; } else { $otherPrice+=$val['value']; } $i++; } if($other) { $arr[$length] = [ $key => '其它', $value => $otherPrice ]; } return $arr; } return $data; } }
评论