# Dividing people into groups

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
Hi im kinda stuck.

Ik have 2000+ (he exact number may vary) people and 4 groups. I want
each first person to go into group 1 , each person in group 2, third
person in groupd 3 and fourt person in group 4.

Thats not really a problem but the following is:

How do i know in wich group person X is without creating the entire
group list ?

Ive tried stuff like if(\$iPersonId % 4 == 1) but that doesnt work.

Any ideas on how to dot his ?

Floortje

## Re: Dividing people into groups

Modulus operations return 0 when an integer is a multiple of the
second operand.

This approach excludes \$iPersonId when it holds 0:

if (\$iPersonId > 0 && \$iPersonId % 4 == 0) {
// group 4 stuff
}

--
Curtis
\$email = str_replace('sig.invalid', 'gmail.com', \$from);

## Re: Dividing people into groups

Floortje schreef:

Should work. Presuming \$iPersonId is an incrementing number from 1 up.

<?php

// start at zero, because we're pre incrementing later on
\$iPersonId = 0;

// pre increment, so \$iPersonId will be accurate inside while loop
while( ++\$iPersonId <= 100 )
{
switch( \$iPersonId % 4 )
{
case 1:
echo 'Person ' . \$iPersonId . ' belongs to group 1<br>' . PHP_EOL;
break;
case 2:
echo 'Person ' . \$iPersonId . ' belongs to group 2<br>' . PHP_EOL;
break;
case 3:
echo 'Person ' . \$iPersonId . ' belongs to group 3<br>' . PHP_EOL;
break;
case 0:
echo 'Person ' . \$iPersonId . ' belongs to group 4<br>' . PHP_EOL;
break;
default:
break;
}
}

?>

## Re: Dividing people into groups

amygdala schreef:

Great !!! Thx ! This does the job perfectly !

Floortje

## Re: Dividing people into groups

Floortje schreef:

Graag gedaan! (You're welcome!) :-)

## Re: Dividing people into groups

amygdala wrote:

He won't learn much if you just give him the answers to his homework.
Rather, you should give him suggestions and let him work it out himself.
He will learn much more from the exercise.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

## Re: Dividing people into groups

Jerry Stuckle schreef:

<snip>

Jerry, have some faith in humanity already. You're making assumptions,
that might be true, but could just as well be very unfounded.

Considering she (pretty sure it's a female ;-) ) was on the right track,
I had enough faith in her ability to grasp the concept through my example.

Also, sometimes I just don't feel like having to type it all out in
human written language. PHP is usualy less effort for me to type. ;-)

Concrete examples can just as well be didactic tools. Speaking for
myself: I usualy learn best with concrete examples.

## Re: Dividing people into groups

amygdala wrote:

Amy, it's my "interpretation" which comes from 19 years of corporate
training experience.  I've been in this business since 1990, and trained
thousands of programmers in that time.

This experience has shown me what helps a person learn and what doesn't.
And just giving them the answer does not teach them nearly as much as
giving them hints and letting them work out the answer for themselves.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

## Re: Dividing people into groups

Its not up to the group to decide what is homework and what is not,
what work for someone and what does not.
And certainly it is not up to Stuckle to decide, since you have been
very wrong on many occasions.

I put this blunt, because I think you can handle it. Its your style,
no?

R.

## Re: Dividing people into groups

amygdala wrote:

Game-Set-Match.

Got you on that one Jerry.  J/K

Scotty

## Re: Dividing people into groups

Scott Johnson wrote:

Sorry, Scotty.  Wrong.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

## Re: Dividing people into groups

Jerry Stuckle wrote:

hehehe

## Re: Dividing people into groups

Jerry Stuckle wrote:

Ys, this looked like a homework assignment to me as well.