Donald Donald - 3 months ago 7
PHP Question

How can i display the array in a page a format

I have to read the following array generated from database and display in a page .

Array :result.php

Array
(
[BC] => Array
(
[Regional Support Centre (Burnaby)] => Array
(
[1] => position1
)

)

[Prairies] => Array
(
[Winnipeg] => Array
(
[2] => Position2
)

)

[Ontario] => Array
(
[Regional Support Centre (Mississauga)] => Array
(
[3] => position3
)

[Mississauga] => Array
(
[4] => position4
[5] => position5
[6] => position6
)

[London] => Array
(
[7] => Technician - Experienced Apprentices
)
)

)


Expected output:
[![enter image description here][1]][1]

Can anyone please help me to how to read the array generated from the database and display it in the page .

Answer

Something like this:

foreach($your_arr as $parent_cat => $sub_arr){
    echo $parent_cat.'<br>';

    if(is_array($sub_arr)){
        foreach($sub_arr as $cat => $items){
            echo '--'.$cat.'<br>';

            if(is_array($items)){
                foreach($items as $val){
                    echo '-----'.$val.'<br>';
                }
            }
        }
    }
}

I've created a tree structure but you can add your HTML in echo statement.