enter image description here

i have one table . and it’s have more rows parent and children

look at this image
“servies” is the parent
and Development and Design is the child
but “Design” must be have a one dash like “Development”
and business card and banner must be under the parent Design
but it’s also not ,
i think that the error in the recursive multidimensional array php
and this is the code

function getCatTable($array, $dash = 0)
{
foreach($array as $cats){
  ?>
  <tr role="row" class="odd">
    <td class="sorting_1 text-right"><?=str_repeat(" - ", $dash) . $cats['page_title_en'];?></td>
  </tr>
  <?php
    if ( ! empty($cats['children']) )
    {
        $dash = $dash +1;
        getCatTable($cats['children'], $dash);
        $dash = 0;
    }
}
}
getCatTable($allCats);

and this my array

    Array
(
    [0] => Array
        (
            [page_id] => 2
            [page_parent] => 0
            [page_title_en] => Services
            [page_active] => 1
            [children] => Array
                (
                    [0] => Array
                        (
                            [page_id] => 6
                            [page_parent] => 2
                            [page_title_en] => Development
                            [page_active] => 1
                            [children] => Array
                                (
                                    [0] => Array
                                        (
                                            [page_id] => 7
                                            [page_parent] => 6
                                            [page_title_en] => Web development
                                            [page_active] => 1
                                            [children] => Array
                                                (
                                                )

                                        )

                                )

                        )

                    [1] => Array
                        (
                            [page_id] => 10
                            [page_parent] => 2
                            [page_title_en] => Design
                            [page_active] => 1
                            [children] => Array
                                (
                                    [0] => Array
                                        (
                                            [page_id] => 12
                                            [page_parent] => 10
                                            [page_title_en] => business card
                                            [page_active] => 1
                                            [children] => Array
                                                (
                                                )

                                        )

                                    [1] => Array
                                        (
                                            [page_id] => 13
                                            [page_parent] => 10
                                            [page_title_en] => Banner
                                            [page_active] => 1
                                            [children] => Array
                                                (
                                                )

                                        )

                                )

                        )

                )

        )

)

Read more here: php array display categories like wordpress admin


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: