I have the following array which consists of simply integers (IDs) within 8 sub arrays. I have 8 groups, and I need the integers from array 1 to go into the first group, array 2 into the second and so on. I intent to use sql inserts to achieve this.
My data is as follows:
Array
(
[0] => Array
(
[0] => 4012
[1] => 3914
[2] => 4054
[3] => 3911
[4] => 4010
[5] => 3979
)
[1] => Array
(
[0] => 3916
[1] => 3946
[2] => 4059
[3] => 3924
[4] => 4018
[5] => 3967
)
[2] => Array
(
[0] => 3983
[1] => 4057
[2] => 3980
[3] => 3901
[4] => 4045
[5] => 3955
)
[3] => Array
(
[0] => 3908
[1] => 3898
[2] => 3939
[3] => 4036
[4] => 4079
[5] => 3479
)
[4] => Array
(
[0] => 3995
[1] => 3910
[2] => 4047
[3] => 3988
[4] => 3965
[5] => 4080
)
[5] => Array
(
[0] => 3925
[1] => 3561
[2] => 4000
[3] => 4061
[4] => 3950
[5] => 4058
)
[6] => Array
(
[0] => 3989
[1] => 3964
[2] => 3904
[3] => 4070
[4] => 3954
[5] => 3984
)
[7] => Array
(
[0] => 3985
[1] => 4044
[2] => 4062
[3] => 4014
[4] => 3899
)
)
The groups I have are:
- Group 01a
- Group 01b
- Group 02a
- Group 02b
- Group 03a
- Group 03b
- Group 04a
- Group 04b
The php I am running works well in that it creates the name of the groups as above, however the foreach which handles the smallgroups array does not work. It duplicates the smallusers 8 times, when I want to have just the first sub array for processing in the loop, then then next.
$count = 0;
foreach ($biggroup as $key => $users) {
$smallgroups = array_chunk($users, ceil(count($users) / 8));
for ($i = 1; $i <= 4; $i++) {
$groupnum = sprintf("%02d", $count * 4 + $i);
foreach (range('a', 'b') as $letter) {
$nameofgroup = 'Group ' . $groupnum . $letter;
foreach ($smallgroups as $f => $smallusers) {
}
}
}
}
$count++;
I expect the following:
Group 01A 4012, 3914, 4054, 911, 4010, 3979
Group 01B 3916, 3946, 4059, 3924, 4018, 3967
etc