I have an output string/array for example of 001100110011. Every fourth character depicts a single unit. I would like to calculate the number of 1's in each unit.
So for the above I would like a return of 2,2,2. If the string was 0100001100111 then It should return 1,2,3.
My current script only counts at every fourth loop so 0100001100111 would return 1,3,6.
$u = 16;//total of entries /4 is one unit
for($i=0;$i<=$u;$i++){
if(($i % 4) == 0){if($i==0){}else {$str .= substr_count($util_end, '1');}}
$util_end .= $_POST['userinput'.$b];
// util_end is the input from user on a checkbox select 0 for unselected and 1 for selected in sets of four ex 0110 (two selected)
}
$input = "010101010001001";
$result = array_map(function($i){
return substr_count($i, "1");
}, str_split($input, 4));