So i am using php for my school works controlled assessment and I need to output an array of user ID's in sections.
However it must function in this way:
So there are 10 UIDS and they must be split and assorted as follows:
Split 1 // The remainder is also not forgotten about
1,4,7,10
Split 2 // Vertical assorted
2,5,8
Split 3
3,6,9
You can just use Modulo for that
<?php
$uids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
$split = [
0 => [],
1 => [],
2 => [],
];
foreach ($uids as $index => $value) {
$split[$index % 3][] = $value;
}
var_dump($split);
Output:
array(3) {
[0]=>
array(4) {
[0]=> int(1)
[1]=> int(4)
[2]=> int(7)
[3]=> int(10)
}
[1]=>
array(3) {
[0]=> int(2)
[1]=> int(5)
[2]=> int(8)
}
[2]=>
array(3) {
[0]=> int(3)
[1]=> int(6)
[2]=> int(9)
}
}