The array has to be organized so that, rather than having each value in the array, the array values of arrays with the values of the data, and each of those nested arrays must have a max number of values.
So it should start with this:
$data = array(
0 => 'Data 1',
1 => 'Data 2',
2 => 'Data 3',
3 => 'Data 4',
4 => 'Data 5',
5 => 'Data 6',
);
and then given that $max = 3;, the array should become this:
$data = array(
0 => array(
0 => 'Data 1',
1 => 'Data 2',
2 => 'Data 3',
),
1 => array(
0 => 'Data 4',
1 => 'Data 5',
2 => 'Data 6',
),
);
I feel like I'm close, but I keep losing the fourth data value when my max is set to 3.
$max_col = 3;
$current_row = 0;
$current_col = 0;
foreach ($data_values as $val) {
if ($current_col < $max_col) {
$new_data[$current_row][$current_col] = $val;
$current_col++;
} else {
$current_col = 0;
$current_row++;
$new_data[$current_row][$current_col] = $val;
}
}
What I end up with is this:
$data = array(
0 => array(
0 => 'Data 1',
1 => 'Data 2',
2 => 'Data 3',
),
1 => array(
0 => 'Data 5',
1 => 'Data 6',
),
);