Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm try get 2 levels array from array tree , And i'm stuck. I have array like this.

Array(
    [4] => Array
        (
            [5] => Array
                (
                    [group_id] => 5
                    [group_parent_group] => 4
                    [group_nesting] => 1
                    [group_short_name] => group_5
                    [group_full_name] => Верхняя одежда
               )

            [6] => Array
                (
                    [group_id] => 6
                    [group_parent_group] => 4
                    [group_nesting] => 1
                    [group_short_name] => group_6
                    [group_full_name] => Обувь
                )

        )

    [6] => Array
        (
            [8] => Array
                (
                    [group_id] => 8
                    [group_parent_group] => 6
                    [group_nesting] => 2
                    [group_short_name] => group_8
                    [group_full_name] => Женская обувь
                )

            [7] => Array
                (
                    [group_id] => 7
                    [group_parent_group] => 6
                    [group_nesting] => 2
                    [group_short_name] => group_7
                    [group_full_name] => Мужская обувь
                )

    [5] => Array
        (
            [10] => Array
                (
                    [group_id] => 10
                    [group_parent_group] => 5
                    [group_nesting] => 2
                    [group_short_name] => group_10
                    [group_full_name] => Зимняя одежда
                )
            )


    [7] => Array
        (
            [9] => Array
                (
                    [group_id] => 9
                    [group_parent_group] => 7
                    [group_nesting] => 3
                    [group_short_name] => group_9
                    [group_full_name] => Кроссовки
                )

        )
)

and i'm make a tree using this function what sort array by group id.

        function resort_array_groups_data($array,$parent_id){
        if(is_array($array) && isset($array[$parent_id])){
            foreach($array[$parent_id] as $cat){
                $tree[$cat['group_id']]['data'] = $cat;
                $tree[$cat['group_id']]['child'] = resort_array_groups_data($array,$cat['group_id']);

            }
            return $tree ;
        } else {
            return null;
        }
    }

        $resort_arr = resort_array_groups_data($no_sort_arr,0);
(
    [4] => Array
        (
            [data] => Array
                (
                    [group_id] => 4
                    [group_parent_group] => 0
                    [group_nesting] => 0
                    [group_short_name] => group_4
                    [group_full_name] => Одежда и Аксессуары

                )

            [child] => Array
                (
                    [5] => Array
                        (
                            [data] => Array
                                (
                                    [group_id] => 5
                                    [group_parent_group] => 4
                                    [group_nesting] => 1
                                    [group_short_name] => group_5
                                    [group_full_name] => Верхняя одежда

                                )

                            [child] => Array
                                (
                                    [10] => Array
                                        (
                                            [data] => Array
                                                (
                                                    [group_id] => 10
                                                    [group_parent_group] => 5
                                                    [group_nesting] => 2
                                                    [group_short_name] => group_10
                                                    [group_full_name] => Зимняя одежда

                                                )

                                            [child] => 
                                        )

                                )

                        )

                    [6] => Array
                        (
                            [data] => Array
                                (
                                    [group_id] => 6
                                    [group_parent_group] => 4
                                    [group_nesting] => 1
                                    [group_short_name] => group_6
                                    [group_full_name] => Обувь

                                )

                            [child] => Array
                                (
                                    [8] => Array
                                        (
                                            [data] => Array
                                                (
                                                    [group_id] => 8
                                                    [group_parent_group] => 6
                                                    [group_nesting] => 2
                                                    [group_short_name] => group_8
                                                    [group_full_name] => Женская обувь

                                                )

                                            [child] => 
                                        )

                                    [7] => Array
                                        (
                                            [data] => Array
                                                (
                                                    [group_id] => 7
                                                    [group_parent_group] => 6
                                                    [group_nesting] => 2
                                                    [group_short_name] => group_7
                                                    [group_full_name] => Мужская обувь

                                                )

                                            [child] => Array
                                                (
                                                    [9] => Array
                                                        (
                                                            [data] => Array
                                                                (
                                                                    [group_id] => 9
                                                                    [group_parent_group] => 7
                                                                    [group_nesting] => 3
                                                                    [group_short_name] => group_9
                                                                    [group_full_name] => Кроссовки

                                                                )

                                                            [child] => 
                                                        )

                                                )

                                        )

                                )

                        )

                )

        )

how i can get new 2 levels array which contains all child arrays, like this , without а tree structure ?

$new_arr = new_function($array,4);

    $new_arr[4] = array(
        5=>true,
        10=>true,
        6=>true,
        8=>true,
        7=>true,
        9=>true,
    );

have any idea ?

share|improve this question
1  
Your question is overwhelming, can you build an example with simple stuff, not all that code! Change that to something we can read :P –  JuanBonnett Feb 8 at 19:27
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.