I'm wondering if this is a better way to do this.

What I'm needing to do is run through a changing group of numbers (actually corresponds to a list of numbers, but I've simplified the script above). I want it to determine which group of ten numbers mu current number is. I also would like the flexibility for this to change to groups of 8 or 5 and I would not like it to have a limit.

So in summary, to be able to sequentially go through a list of x numbers and determine which group the current number is in with a variable group size.

```
$input = 29;
for ($i = 0; $i < $input; $i++) {
if ($i <=10) $isGrp = 1;
elseif ($i <=20) $isGrp = 2;
elseif ($i <=30) $isGrp = 3;
elseif ($i <=40) $isGrp = 4;
elseif ($i <=50) $isGrp = 5;
print 'The number ['.$i.'] is in group ['.$isGrp.']<br />';
} //
```

What I'm needing to do is run through a changing group of numbers (actually corresponds to a list of numbers, but I've simplified the script above). I want it to determine which group of ten numbers mu current number is. I also would like the flexibility for this to change to groups of 8 or 5 and I would not like it to have a limit.

So in summary, to be able to sequentially go through a list of x numbers and determine which group the current number is in with a variable group size.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with Premium.
Start your 7-day free trial.

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

```
$group = 6;
$input = 29;
$iterations = ceil($input / $group);
for ($x = 0; $x < $iterations; $x++)
{
for ($i = 0; $i < $input; $i++) {
if (($i > $group * ($x)) && ($i <= $group * ($x+1))) {
$isGrp = $x+1;
print 'The number ['.$i.'] is in group ['.$isGrp.']<br />';
}
}
}
```

Just change the value of $group to try different groups.
Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trialIn the line 6 for loop the qualifier needs to be less than or equal to. Otherwise it doesn't give the correct answer.

I've now created this function that I reference.

```
function quantile($curPos, $group, $totSize) {
// $curPos = current position (to determine which group you are in)
// $group = the size iterations of the group
// $totSize = total size of sample to knoww when you're done.
$iterations = ceil($totSize / $group);
if ($curPos > $totSize) return $iterations;
elseif (numbIt($curPos, "not")) return 1;
for ($x = 0; $x < $iterations; $x++) {
for ($i = 0; $i <= $totSize; $i++) {
if (($i > $group * ($x)) && ($i <= $group * ($x+1))) {
$isGrp = $x+1;
if ($curPos == $i) return $isGrp;
}
} // for ($i = 0; $i < $totSize; $i++) {
} // for ($x = 0; $x < $iterations; $x++) {
return 0; // if you get this far it is an error and it returns zero
} // function quantiles
```

```
for ($i = 0; $i < $input; $i++) {
```

should be```
for ($i = 0; $i <= $input; $i++) {
```

?But this way, if $input is 29, starting the loop at 0 you get 30 element, not 29. If this is what you want, well, but I did the code in order to allow to use as input the exact value of the desired return amount.

Anyway, I'm glad to help you :-) Cheers

PHP

From novice to tech pro — start learning today.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with Premium.
Start your 7-day free trial.

design pattern. Commonly used groupings include quartiles (four), quintiles (five), stanines (nine), percentiles (100), etc. You make a distribution of the values and then chop the distribution up into the groups. Here is my teaching example that illustrates the principles. You can experiment with the settings forquantilesq=andn=here:http://iconoun.com/demo/quantiles.php

Open in new window