0

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

Edited by chaitu11

2
Contributors
1
Reply
14
Views
2 Years
Discussion Span
Last Post by diafol
0

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>";
    }
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.