I am wondering how to get a certain percentage of an array.
Say:
$array = array ("I","am","not","a","professional","coder","so","please","help","me");
It consists of ten meanings.
I would like to write a method to get a fragment of it.
public function get_percentage($percentage) {...;return $array_sliced;}
So, if I need an array containing only "I", I would use
$this->get_percentage(10) //10 stands for 10% //returns $slice = array ("I");
It would also be great if $ num could be rounded to the nearest usable value. For instance:.
$this->get_percentage(8)
I did not find a similar question here, I hope that this is not too difficult.
source share