0

I have this array:

$arr = array(
    '17-GUIDO HUMBERTO -3 ', 
    array( 
        '2-José-3'
    ),
    array(
        array(
            '18-juan andres-3'
        ),
    ),
    '17-luis -3 '
);

I have this function:

function listArr($arr) {
    $html = '<ul>';
    foreach ($arr as $item) {
        if (is_array($item)) {
            $html .= listArr($item); // <<< here is the recursion
        } else {
            $html .= '<li>' . $item . '</li>';
        }
    }

    $html .= '</ul>';
    return $html;
}
echo(listArr($tree));

Then I add HTML:

<div class="row">
            <div class="col-md-12">
                <div class="row">
                    <div id="jstree">
                        <?php
                            echo(listArr($tree));
                        ?>
                    </div>
                </div>
            </div>
            <!-- /.col-md-12 -->
        </div>

How can I put 18-juan andres-3 under 17-GUIDO HUMBERTO -3 AND 17-luis -3 under 18-juan andres-3

17-luis -3 Under 18-juan andres-3 Under 17-GUIDO HUMBERTO -3 (This is the top)

How should I put the array to work properly with jstree? Please Help Thanks!!

Haotian Liu
  • 886
  • 5
  • 19
Jesús Cova
  • 339
  • 3
  • 18

1 Answers1

0

The problem is with your array because they are at different level. Chage your array to this:

$arr = array(
        '17-GUIDO HUMBERTO -3 ',
        array(
                '2-Jose-3'
        ),
        array(
                'label',
                array(
                        '18-juan andres-3',
                        array('17-luis -3 '),
                ),
        ),

);

and i don't see any $tree declared.

call like:

echo(listArr($arr));

OUTPUT:

17-GUIDO HUMBERTO -3
  -- 2-Jose-3
  -- label
  ---  18-juan andres-3
  ----   17-luis -3
Suchit kumar
  • 11,809
  • 3
  • 22
  • 44