【发布时间】:2012-02-11 00:05:33
【问题描述】:
我想知道如何获得一个确定百分比的数组。
假设:
$array = array ("I","am","not","a","professional","coder","so","please","help","me");
它由十个值组成。
我想写一个方法来获取它的一部分。
public function get_percentage($percentage) {...;return $array_sliced;}
所以如果我想要一个只包含“I”的数组,我会使用
$this->get_percentage(10) //10 stands for 10%
//returns $slice = array ("I");
另外,如果 $num 可以四舍五入到最接近的有用值,那就太好了。例如:
$this->get_percentage(8) //8 stands for 8% but the function will treat this as 10%
//returns $slice = array ("I");
我在这里没有找到任何类似的问题,希望这不是太复杂。
【问题讨论】:
-
“希望这不是太复杂”:让编码器为您工作的最佳方式!