Voting

: nine minus three?
(Example: nine)

The Note You're Voting On

Anonymous
11 years ago
Couldn't get the array_chunk_values() working, so ended up with this implementation:

<?php
function array_chunk_columns($data, $num_columns) {
$n = count($data);
$per_column = floor($n / $num_columns);
$rest = $n % $num_columns;

$columns = array();
$index = 0;
for (
$i = 0; $i < $num_columns; $i++) {
// Add an extra item to each column while the column number is less than the
// remainder.
$add_rest = ($rest && ($i < $rest)) ? 1 : 0;
$number = $per_column + $add_rest;
$columns[] = array_slice($data, $index, $number);
$index += $number;
}

return
$columns;
}

?>

<< Back to user notes page

To Top