Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $chunk = 4;
- $arr = array('1', '1', '1', '1', '1', '1', '1', '0', '1', '0', '1', '0', '0', '0', '0', '1');
- 1110
- 1101
- 1110
- 1001
- there are 4 number '1' in first column, so the output should be 4
- function array_chunk_vertical($arr, $percolnum){
- $n = count($arr);
- $mod = $n % $percolnum;
- $cols = floor($n / $percolnum);
- $mod ? $cols++ : null ;
- $re = array();
- for($col = 0; $col < $cols; $col++){
- for($row = 0; $row < $percolnum; $row++){
- if($arr){
- $re[$row][] = array_shift($arr);
- }
- }
- }
- return $re;
- }
- $result = array_chunk_vertical($arr, $chunk);
- $new = 0;
- $exist = 0;
- foreach($result as $row){
- foreach($row as $val){
- if($val == "1"){
- $new++;
- }
- else{
- $exist++;
- }
- echo $val;
- }
- echo '<br/>';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement