Hi,

I have an array as:

$data = array (
array ('add1','add2','May 2014','ascascascasc',160),
array ('Framework','hii','May 2014','ascascasc',161 ),
array ('Framework','test framework 1','May 2014','asdasdasd',159 )
array ('Framework','test framework','May 2014','asdasdasd',149 )
array ('OS','other OS skill','May 2014','ascascASC',162 ),
array ('Databases','test db skill 3','May 2014','bnmbnmbnm',158 ),
array ('Databases','test db','May 2014','bnmbnmbnm',18 ),
); 

I want to print this array in html format.
but the same type of o'th index in one table.

as:
table:1
'add1','add2','May 2014','ascascascasc',160

table:2
'Framework','hii','May 2014','ascascasc',161
'Framework','test framework 1','May 2014','asdasdasd',159
'Framework','test framework','May 2014','asdasdasd',149

table:3
'OS','other OS skill','May 2014','ascascASC',162

table:4
'Databases','test db skill 3','May 2014','bnmbnmbnm',158
'Databases','test db','May 2014','bnmbnmbnm',18

how can I do this using while and for loop

Hi,
Try this simple:

<?php
    $data = array (
    array ('add1','add2','May 2014','ascascascasc',160),
    array ('Framework','hii','May 2014','ascascasc',161 ),
    array ('Framework','test framework 1','May 2014','asdasdasd',159 ),
    array ('Framework','test framework','May 2014','asdasdasd',149 ),
    array ('OS','other OS skill','May 2014','ascascASC',162 ),
    array ('Databases','test db skill 3','May 2014','bnmbnmbnm',158 ),
    array ('Databases','test db','May 2014','bnmbnmbnm',18 ),
    );

    $count1 = count($data);
    $tab = "";
    $new_tab = "";
    $html = "";
    for($i = 0; $i<$count1; $i++)
    {
        $tab = $data[$i][0];
        if($new_tab != $tab)
        {
            if($tab != "")
            {
                $html .= "</table><br/>";
            }
            $new_tab = $tab;
            $html .= "<table>";
            //You can create header table here if you need
            //.....
            //First row of subarray
            $html .= row_render($data[$i]);
        }
        else
        {
            $html .= row_render($data[$i]);    
        }     
    }
    echo $html;



    function row_render($array)
    {
        $retval = "<tr>";
        $count = count($array);
        for($k = 0; $k<$count; $k++)
        {
            $retval .= "<td>".$array[$k]."</td>";        
        }
        $retval .= "</tr>";
        return $retval;    
    }


?>
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.