Jump to content

4 column result


Canman2005

Recommended Posts

Hi all

 

I have the following code

 

<?php

$array = array(1,2,3,4,5,6,7,8,9,10,11,12,13);

$cols = 3;

$count = count($array);

 

if($count%$cols > 0){

for($i=0;$i<($cols-$count%$cols);$i++){

$array[] = ' ';

}

}

echo "<table border=\"1\">\r\n";

 

foreach($array as $key => $td){

if($key%$cols == 0) echo "<tr>\r\n";

echo "<td>$td</td>\r\n";

if($key%$cols == ($cols - 1)) echo "</tr>\r\n";

}

echo "</table>";

?>

 

which works great and returns something like

 

1 2 3 4

5 6 7 8

9 10 11 12

13

 

but is it possible to change this so that it orders the results like

 

1 5 9 13

2 6 10

3 7 11

4 8 12

 

any help would be great

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/200446-4-column-result/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.