Hi there, I am trying to divide a single array into multiple arrays using a $variable. The $variable is the number of fields / columns in my db table.

For example, if $variable = 3...

Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
[6] => 7
[7] => 8
[8] => 9
[9] => 10
[10] => 11
[11] => 12
)

Would become...

Array1
(
[0] => 1
[1] => 4
[2] => 7
[3] => 10
)

Array2
(
[0] => 2
[1] => 5
[2] => 8
[3] => 11
)

Array3
(
[0] => 3
[1] => 6
[2] => 9
[3] => 12
)

If someone knows of an easy way to do this would be of great help.
Thanks

It's all good I figured it out...

for($n=0; $n<$num_fields; $n++){
    for($i=0; $i<$num_rows; $i++){
$rows[] = mysql_result($this->total,$i,$field_array[$n]);}
}

$rows = array_chunk($rows, $num_rows);

This returns a multi-dimensional array.

Thanks anyway.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.