PHP5 grouping algorithm (1) split a set of data into six output algorithms? $ GroupCount6; number of groups $ userIdListarray (,); $ sizecount ($ userIdList); $ sizeGroupPerfloor ($ size $ groupCount ); PHP 5 grouping algorithm (1)
Split a group of data into six output algorithms
?
$ GroupCount = 6; // number of groups
$ UserIdList = array (1, 2, 3, 4, 5, 6, 7, 8, 9, 10 );
$ Size = count ($ userIdList );
$ SizeGroupPer = floor ($ size/$ groupCount); // The number of groups allocated.
$ CriticalValue = $ size % $ groupCount; // critical value
$ StartIndex = 0;
$ EndIndex = 0;
For ($ I = 0; $ I <$ groupCount; $ I ++ ){?
?
??????????? If ($ I <$ critical) {// indicates which groups can be assigned multiple times
?????????????? $ EndIndex = $ startIndex + $ sizeGroupPer + 1;
????????????} Else {
??????????????? $ EndIndex = $ startIndex + $ sizeGroupPer;
????????????}
??
???????????? $ StrGroup = "";?
??????????? For ($ j = $ startIndex; $ j <$ endIndex; $ j ++ ){
?????????????? If ($ j + 1) ==$ ){
?????????????????? $ StrGroup. = $ arryData [$ j];
?????????????? } Else {
?????????????????? $ StrGroup. = $ arryData [$ j]. ","; ???
?????????????? }
??????????? }
?
?????????? $ StartIndex = $ endIndex;
???????? Echo? "No.". $ I. "group data:". $ strGroup ;?
}
?