How to loop them out?

print_r($tree) result is

Array
(
    [0] => stdClass Object
        (
            [tid] => 6
            [vid] => 2
            [name] => parent one
            [description] =>
            [format] => filtered_html
            [weight] => 0
            [depth] => 0
            [parents] => Array
                (
                    [0] => 0
                )

        )

    [1] => stdClass Object
        (
            [tid] => 14
            [vid] => 2
            [name] => child one
            [description] =>
            [format] => filtered_html
            [weight] => 0
            [depth] => 1
            [parents] => Array
                (
                    [0] => 6
                )

        )

    [2] => stdClass Object
        (
            [tid] => 13
            [vid] => 2
            [name] => child tow
            [description] =>
            [format] => filtered_html
            [weight] => 0
            [depth] => 1
            [parents] => Array
                (
                    [0] => 6
                )

        )

    [3] => stdClass Object
        (
            [tid] => 7
            [vid] => 2
            [name] => parent two
            [description] =>
            [format] => filtered_html
            [weight] => 1
            [depth] => 0
            [parents] => Array
                (
                    [0] => 0
                )

        )

    [4] => stdClass Object
        (
            [tid] => 18
            [vid] => 2
            [name] => child three
            [format] => filtered_html
            [weight] => 0
            [depth] => 1
            [parents] => Array
                (
                    [0] => 7
                )

        )

    [5] => stdClass Object
        (
            [tid] => 19
            [vid] => 2
            [name] => child four
           [format] => filtered_html
            [weight] => 0
            [depth] => 1
            [parents] => Array
                (
                    [0] => 7
                )

        )

    [6] => stdClass Object
        (
            [tid] => 8
            [vid] => 2
            [name] =>parent
            [description] =>
            [format] => filtered_html
            [weight] => 2
            [depth] => 0
            [parents] => Array
                (
                    [0] => 0
                )

        )

    [7] => stdClass Object
        (
            [tid] => 4
            [vid] => 2
            [name] => parent
            [description] =>
            [format] => filtered_html
            [weight] => 3
            [depth] => 0
            [parents] => Array
                (
                    [0] => 0
                )

        )

i want to output the hml like the following:

<li class='parent'><a href="#">parent one</a><span></span>
<ul class='haschild'>
<li><a href="#">child one/a></li>
<li><a href="#">child two</a></li>
</ul>
</li>
<li class='parent'><a href="">parent two</a><span></span>
<ul class='haschild'>
<li><a href="">child three</a></li>
<li><a href="9">child four</a></li>
</ul>
</li>
<li><a href="">parent</a></li>
<li><a href="">parent</a></li>

http://www.php.net/foreach

Can a child have more than one parent? Can a parent have more than one child? A simple foreach will not do here.

a child have only one child,a parent maybe have more than one child?

foreeach($tree as $term){

if($term->path==0){
echo “<li class=‘parent’><a href=‘’>$term->name</li>”;
}
if()…

i don’t now how to write the code. could you give me withe more details.

if it has child add class=‘parent’ to the li, add the ul out of all the child li