Recursive function for multidimensional array

Posted by moja on Stack Overflow See other posts from Stack Overflow or by moja
Published on 2012-10-17T22:58:34Z Indexed on 2012/10/17 23:00 UTC
Read the original article Hit count: 128

Filed under:

This is my code, and I need your help to understand it.

<?php $tree = array(
array(
    'name' => 'Item-1', 
    'children' => array()),

array('name' => 'Item-2', 
    'children' => array(
    array('name' => 'Item-2-1', 
        'children' => array()),
)),
array('name' => 'Item-3', 
    'children' => array(
    array('name' => 'Item-3-1', 
        'children' => array()),

    array('name' => 'Item-3-2', 
        'children' => array(
        array('name' => 'Item-3-2-1', 
            'children' => array()),

        array('name' => 'Item-3-2-2', 
            'children' => array()),

        array('name' => 'Item-3-2-3', 
            'children' => array(
            array('name' => 'Item-3-2-3-1', 
                'children' => array()),
        )),
    )),
)),

);

What i need is one recursive function, which will return all names (name). For example:

Item-1
Item-2
Item-2-1
Item-3
Item-3-1
Item-3-2

........

Thanks for your help.

© Stack Overflow or respective owner

Related posts about php