Location: PHPKode > scripts > Walker > test.php
<?php
	require 'walker.class.php';
    $cats = array(
        0 => array(
            'id' => '1',
            'name' => 'Cat 1',
            'parentId' => 6
        ),
        1 => array(
            'id' => '2',
            'name' => 'Cat 2',
            'parentId' => 1
        ),
        2 => array(
            'id' => '3',
            'name' => 'Cat 3',
            'parentId' => 1
        ),
        3 => array(
            'id' => '4',
            'name' => 'Cat 4',
            'parentId' => 3
        ),
        4 => array(
            'id' => '5',
            'name' => 'Cat 5',
            'parentId' => 10
        ),
        5 => array(
            'id' => '6',
            'name' => 'Cat 6',
            'parentId' => 0
        ),
        6 => array(
            'id' => '7',
            'name' => 'Cat 7',
            'parentId' => 5
        ),
        7 => array(
            'id' => '8',
            'name' => 'Cat 8',
            'parentId' => 6
        ),
        8 => array (
            'id' => 9,
            'name' => 'Cat 9',
            'parentId' => 5,
        ),
        9 => array (
            'id' => 10,
            'name' => 'Cat 10',
            'parentId' => 0,
        ),
        10 => array (
            'id' => 11,
            'name' => 'Cat 11',
            'parentId' => 9,
        ),
    );
    
    
    
    class Walker_Test extends Walker {
        protected function _element($element, $depth) {
            return str_repeat('--', $depth) . $element['name'] . "<br />\r\n";
        }
    }
    // can handle the set of arrays
    $w = new Walker_Test($cats, 'id', 'parentId');
    echo $w->result(); // or just echo $w;
    
    
    
    //as well as the set of objects
    
    foreach ($cats as &$cat) {
        $cat = (object)$cat;
    }
    
    class Walker_Test2 extends Walker {
        protected function _element($element, $depth) {
            return '<option value="' . $element->id . '">' . str_repeat('>>', $depth) . $element->name . "</option>\r\n";
        }
        
        protected function _beforeElements() {
            return '<select>';
        }
        protected function _afterElements() {
            return '</select>';
        }
    }
    
    $w2 = new Walker_Test2($cats, 'id', 'parentId');
    echo $w2;
    
    
?>
Return current item: Walker