php - How can I use array_chunk and define the size of each chunk? -


i counting number of results in each array first , print them this:

if ($array_count == '12'){      $output = '<div class="row">';     $cat_array = array_chunk((array)$cat_array, 3);     foreach($cat_array $column) {         $output .= '<div class="col-xs-3">';         foreach ($column $row) {            $output .= '<div class="row"><div class="col-xs-12"><small><a href="' .                        $row['subcat_link'] . '" class="cat_filter_link">' . $row['name'] . '</a></small></div></div>';         }         $output .= '</div>';     }     $output .= '</div>';      } 

in case, putting 3 each chunk. there easy way define, if possible, want 4 chunks of 5,3,2,2?

you can use array_slice

$arr = array(1,2,3,4,5,6,7,8,9,10,11,12); $result[0] = array_slice($arr, 0,5); $result[1] = array_slice($arr, 5,3); $result[2] = array_slice($arr, 8,2); $result[3] = array_slice($arr, 10,2); 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -