1
$groups = array("Group1"=>array("V1"=>array(1,2,3,4,5),
                                "V2"=>array(2,3,4,5,6),
                                "V3"=>array(3,4,5,6,7)
                                ),
                "Group2"=>array("V1"=>array(11,22,33,44,55),
                                "V2"=>array(11,21,31,41,51),
                                "V3"=>array(12,23,34,45,56)
                                ),
                "Group3"=>array("V1"=>array(1,2,3,4,5),
                                "V2"=>array(1,2,3,4,5),
                                "V3"=>array(1,2,3,4,5)
                                ),
                "Group4"=>array("V1"=>array(1,2,3,4,5),
                                "V2"=>array(1,2,3,4,5),
                                "V3"=>array(1,2,3,4,5)
                                ),
                "Group5"=>array("V1"=>array(1,2,3,4,5),
                                "V2"=>array(1,2,3,4,5),
                                "V3"=>array(1,2,3,4,5)
                                )                
                );

I want to display from this array to html table some thing like this

     Group1          | Group2
     h1|h2|h3|h4|h5  | h1|h2|h3|h4|h5
V1   value of its       value of its
V2   value of its       value of its
V3

    Group3          |  Group4
    h1|h2|h3|h4|h5  |  h1|h2|h3|h4|h5
V1   value of its       value of its
V2   value of its       value of its
V3   value of its       value of its

    Group5          | 
    h1|h2|h3|h4|h5  | 
V1   value of its     
V2   value of its     
V3   value of its     

I am trying to do like this:

 $g_list = array_keys($groups);
echo '<table border=1>';
for($g=0;$g<=sizeOf($groups);$g++){  
    if(($g+1)<sizeOf($groups)){
        echo "<tr>
                <td COLSPAN=6 ALIGN=center>".$g_list[$g]."</td>
                <td COLSPAN=6 ALIGN=center>".$g_list[$g+1]."</td></tr>";
        echo "<tr>
                <td>&nbsp</td><td>h1</td><td>h2</td><td>h3</td><td>h4</td><td>h5</td>
                <td>&nbsp</td><td>h1</td><td>h2</td><td>h3</td><td>h4</td><td>h5</td>
            </tr>";
         echo "<tr>
                <td>V</td>
                </tr>";
       //todo
    }
}

I could not find it out? Anybody could help me in php?

1
  • yes.,there are more than that,but i display 2 by 2 Commented Jul 10, 2011 at 20:50

2 Answers 2

1

Here- Not great, but works :)

foreach($groups as $group_name=>$group){

    echo '<table>';
    echo '<tr>';
    echo '<td>h1</td><td>h2</td><td>h3</td><td>h4</td><td>h5</td>';

    foreach($group as $version=>$values){


        echo '<tr><td>'.$version.'</td>';
        foreach($values as $value){
            echo '<td>'.$value.'</td>';
        }
        echo '</tr>';
    }

    echo '</table>';
}
Sign up to request clarification or add additional context in comments.

1 Comment

you code show one group by one group only,and use alot of <table>.just put it in one table
1

nested loops:

<?php
foreach ($groups as $group => $rows) {
      ....
        foreach ($group as $row_name => $row) {
           ?> <tr><td><?=$row_name ?></TD> <?
           foreach ($row as $value) {
              ?><td><?=$value?></TD><?
           }   
          ...
        }  
      ...
    }
?>

to disp 2 by to use a counting var + use Modulus (%) to know when to start a new line

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.