[ create a new paste ] login | about

Link: http://codepad.org/y30JDXWy    [ raw code | output | fork ]

PHP, pasted on Dec 8:
<?php
$arr = array(
      0 => '3,6',
      3 => '4,5',
      4 => '7,8',
      8 => '9',
    );
    function writeList($items){
        global $arr;
        echo '<ul>';
        
        $items = explode(',', $items);
        foreach($items as $item){
            echo '<li>'.$item;
            if(isset($arr[$item]))
                writeList($arr[$item]);
            echo '</li>';
        }
    
        echo '</ul>';
    }
    writeList($arr[0]);


Output:
1
<ul><li>3<ul><li>4<ul><li>7</li><li>8<ul><li>9</li></ul></li></ul></li><li>5</li></ul></li><li>6</li></ul>


Create a new paste based on this one


Comments: