Created
July 9, 2014 19:06
-
-
Save mberberoglu/d3e1e33bf73a4555721c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$category = 8; | |
$data = array( | |
164, 150, 132, 144, 125, 149, 145, 146, | |
158, 140, 147, 136, 148, 152, 144, 168, | |
126, 138, 176, 163, 119, 154, 165, 146, | |
173, 142, 147, 135, 153, 140, 135, 161, | |
145, 135, 142, 150, 156, 145, 128, 157 | |
); | |
$min = min($data); | |
$max = max($data); | |
$limit = ceil(($max - $min) / $category); | |
sort($data); | |
for ($i = 0; $i < $category; $i++) { | |
$count = 0; | |
foreach ($data as $key => $number) { | |
if ($number <= (($min + ($limit - 1)) + ($i * $limit))) { | |
$count++; | |
unset($data[$key]); | |
} | |
} | |
echo ($min + ($i * $limit)) . '-' . (($min + ($limit - 1)) + ($i * $limit)) . ' => ' . $count.'<br>'; | |
} | |
//Output | |
119-126 => 3 | |
127-134 => 2 | |
135-142 => 9 | |
143-150 => 13 | |
151-158 => 6 | |
159-166 => 4 | |
167-174 => 2 | |
175-182 => 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this!