Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // You can count how many occurences are there, and then calculate the percentage of each.
- $statusArr = [
- 'On Track',
- 'Not Started',
- 'On Track',
- 'Stuck',
- 'Completed',
- 'Stuck',
- 'On Track',
- 'Completed'
- ];
- $percentages = [];
- foreach($statusArr as $value) {
- $percentages[$value] = isset($percentages[$value]) ? ++$percentages[$value] : 1;
- }
- $scalar = 100 / count($statusArr);
- foreach ($percentages as $key => $count) {
- $percentages[$key] = $scalar * $count;
- }
- print_r($percentages);
- /*
- [On Track] => 37.5
- [Not Started] => 12.5
- [Stuck] => 25
- [Completed] => 25
- */
Add Comment
Please, Sign In to add comment