This is my array

Array
(
    [33] => Array
        (
            [for sale] => Array
                (
                    [1] => villas
                    [2] => plots
                    [3] => flats
                    [4] => houses
                )

        )

    [34] => Array
        (
            [for rent] => Array
                (
                    [5] => in house
                    [6] => appartment
                    [7] => godams
                )

        )

    [35] => Array
        (
            [hostels] => Array
                (
                    [8] => boys
                    [9] => girls
                )

        )

    [36] => Array
        (
            [pg accommodation] => Array
                (
                    [10] => boys
                    [11] => girls
                )

        )

)

and my php code is this..

while($row = mysql_fetch_array($select4)){
    $final[$row['child_category_id']][$row['child_category_name']][$row['sub_child1_category_id']] = $row['sub_child1_category_name'];

}
echo '<pre>';print_r($final);echo'</pre>';



foreach($final as $k1 => $arr1)
{

    foreach($arr1 as $k2 => $arr2){
           echo '<b>'.$k2.'</b><br>';
        foreach($arr2 as $subcat){
            echo $subcat.'<br/>';
        }

    }
}

It displays the records like this

for sale
villas
plots
flats
houses

for rent
in house
appartment
godams

hostels
boys
girls

pg accommodation
boys
girls

How to align them inline..
i need to display 2 records in a row

eg:

For sale and For rent with sub categories in 1 row

Then

hostels and pg accomodation in another row

Member Avatar for diafol

You can use the implode() function to get a list of subcats:

foreach($final as $k1 => $arr1)
{
    foreach($arr1 as $k2 => $arr2){
           echo '<p><strong>'.$k2.'</strong></p>';
           echo "<p>" . implode(", ", $arr2) . "</p>";
    }
}
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.