Benim döngü şey recursive olun

0 Cevap php

Ben oldukça bu başımı alamıyorum. Ben bu yüzden böyle bir dizi var:

Array
(
    [0] => Array
        (
            [content_id] => 23
            [content_level] => 1
            [content_left] => 2
            [content_right] => 3
            [content_type] => link
            [content_url] => 
            [content_name] => home
            [content_link] => a:3:{s:3:"url";s:7:"_link_/";s:6:"target";s:5:"_self";s:5:"title";s:4:"home";}
            [date_modified] => 2010-07-16 10:29:44
            [content_path] => 
        )

    [1] => Array
        (
            [content_id] => 13
            [content_level] => 1
            [content_left] => 12
            [content_right] => 23
            [content_type] => page
            [content_url] => company
            [content_name] => company
            [content_link] => 
            [date_modified] => 2010-08-13 12:55:44
            [content_path] => company
        )

    [2] => Array
        (
            [content_id] => 25
            [content_level] => 2
            [content_left] => 13
            [content_right] => 14
            [content_type] => page
            [content_url] => About-Us
            [content_name] => About Us
            [content_link] => 
            [date_modified] => 2010-08-13 11:13:40
            [content_path] => company/About-Us
        )

    [3] => Array
        (
            [content_id] => 28
            [content_level] => 2
            [content_left] => 15
            [content_right] => 16
            [content_type] => page
            [content_url] => Tecnic-Quality
            [content_name] => Tecnic Quality
            [content_link] => 
            [date_modified] => 2010-08-13 12:40:23
            [content_path] => company/Tecnic-Quality
        )

    [4] => Array
        (
            [content_id] => 29
            [content_level] => 2
            [content_left] => 17
            [content_right] => 18
            [content_type] => page
            [content_url] => Why-Choose-Tecnic
            [content_name] => Why Choose Tecnic
            [content_link] => 
            [date_modified] => 2010-08-13 12:45:56
            [content_path] => company/Why-Choose-Tecnic
        )

    [5] => Array
        (
            [content_id] => 30
            [content_level] => 2
            [content_left] => 19
            [content_right] => 20
            [content_type] => page
            [content_url] => Tecnic-Functionality
            [content_name] => Tecnic Functionality
            [content_link] => 
            [date_modified] => 2010-08-13 12:50:06
            [content_path] => company/Tecnic-Functionality
        )

    [6] => Array
        (
            [content_id] => 31
            [content_level] => 2
            [content_left] => 21
            [content_right] => 22
            [content_type] => page
            [content_url] => Customer-Focus
            [content_name] => Customer Focus
            [content_link] => 
            [date_modified] => 2010-08-13 12:55:44
            [content_path] => company/Customer-Focus
        )

    [7] => Array
        (
            [content_id] => 16
            [content_level] => 1
            [content_left] => 24
            [content_right] => 59
            [content_type] => module
            [content_url] => products
            [content_name] => products
            [content_link] => 
            [date_modified] => 2010-08-13 14:19:44
            [content_path] => products
        )

    [8] => Array
        (
            [content_id] => 17
            [content_level] => 2
            [content_left] => 25
            [content_right] => 32
            [content_type] => module
            [content_url] => SkyMax-Series
            [content_name] => SkyMax Series
            [content_link] => 
            [date_modified] => 2010-08-13 13:24:18
            [content_path] => products/SkyMax-Series
        )

    [9] => Array
        (
            [content_id] => 0
            [content_name] => SkyMax Patio Retractable Roof System
            [content_path] => products/SkyMax-Series/SkyMax-Patio-Retractable-Roof-System-1281674658
            [content_item] => 1
            [content_level] => 3
            [content_left] => 25
            [content_right] => 32
            [content_type] => page
            [date_modified] => 2010-08-13 15:14:36
        )

    [10] => Array
        (
            [content_id] => 0
            [content_name] => SkyMax Fleetwood Retractable Roof system
            [content_path] => products/SkyMax-Series/skyMax-fleetwood-Retractable-Roof-system
            [content_item] => 1
            [content_level] => 3
            [content_left] => 25
            [content_right] => 32
            [content_type] => page
            [date_modified] => 2010-08-13 15:14:36
        )

Ve ben buna döngü gerekir ve güzel content_path dayalı bir şey çevirmek. Ben content_id, isim, yol vb ve diğer menü öğeleri ile ilgili elemanların kalanını içeren eleman "kalemi" ile çok boyutlu bir dizi olmak istiyorum.

Bu benim kodudur:

foreach($menu as $key => $item)
        {
            $parts = explode('/',$item['content_path']);
            switch (count($parts))
            {
            case 3:
                $ul[$parts[0]][$parts[1]][$parts[2]]['item'] = $item;
                break;
            case 2:
                $ul[$parts[0]][$parts[1]]['item'] = $item;
                break;
            case 1:
                $ul[$parts[0]]['item'] = $item;
                break;
            }
        }

Bu çıkış olmak, çalışıyor

    Array
(
    [] => Array
        (
            [item] => Array
                (
                    [content_id] => 23
                    [content_level] => 1
                    [content_left] => 2
                    [content_right] => 3
                    [content_type] => link
                    [content_url] => 
                    [content_name] => home
                    [content_link] => a:3:{s:3:"url";s:7:"_link_/";s:6:"target";s:5:"_self";s:5:"title";s:4:"home";}
                    [date_modified] => 2010-07-16 10:29:44
                    [content_path] => 
                )

        )

    [company] => Array
        (
            [item] => Array
                (
                    [content_id] => 13
                    [content_level] => 1
                    [content_left] => 12
                    [content_right] => 23
                    [content_type] => page
                    [content_url] => company
                    [content_name] => company
                    [content_link] => 
                    [date_modified] => 2010-08-13 12:55:44
                    [content_path] => company
                )

            [About-Us] => Array
                (
                    [item] => Array
                        (
                            [content_id] => 25
                            [content_level] => 2
                            [content_left] => 13
                            [content_right] => 14
                            [content_type] => page
                            [content_url] => About-Us
                            [content_name] => About Us
                            [content_link] => 
                            [date_modified] => 2010-08-13 11:13:40
                            [content_path] => company/About-Us
                        )

                )

            [Tecnic-Quality] => Array
                (
                    [item] => Array
                        (
                            [content_id] => 28
                            [content_level] => 2
                            [content_left] => 15
                            [content_right] => 16
                            [content_type] => page
                            [content_url] => Tecnic-Quality
                            [content_name] => Tecnic Quality
                            [content_link] => 
                            [date_modified] => 2010-08-13 12:40:23
                            [content_path] => company/Tecnic-Quality
                        )

                )

            [Why-Choose-Tecnic] => Array
                (
                    [item] => Array
                        (
                            [content_id] => 29
                            [content_level] => 2
                            [content_left] => 17
                            [content_right] => 18
                            [content_type] => page
                            [content_url] => Why-Choose-Tecnic
                            [content_name] => Why Choose Tecnic
                            [content_link] => 
                            [date_modified] => 2010-08-13 12:45:56
                            [content_path] => company/Why-Choose-Tecnic
                        )

                )

            [Tecnic-Functionality] => Array
                (
                    [item] => Array
                        (
                            [content_id] => 30
                            [content_level] => 2
                            [content_left] => 19
                            [content_right] => 20
                            [content_type] => page
                            [content_url] => Tecnic-Functionality
                            [content_name] => Tecnic Functionality
                            [content_link] => 
                            [date_modified] => 2010-08-13 12:50:06
                            [content_path] => company/Tecnic-Functionality
                        )

                )

            [Customer-Focus] => Array
                (
                    [item] => Array
                        (
                            [content_id] => 31
                            [content_level] => 2
                            [content_left] => 21
                            [content_right] => 22
                            [content_type] => page
                            [content_url] => Customer-Focus
                            [content_name] => Customer Focus
                            [content_link] => 
                            [date_modified] => 2010-08-13 12:55:44
                            [content_path] => company/Customer-Focus
                        )

                )

        )

    [products] => Array
        (
            [item] => Array
                (
                    [content_id] => 16
                    [content_level] => 1
                    [content_left] => 24
                    [content_right] => 59
                    [content_type] => module
                    [content_url] => products
                    [content_name] => products
                    [content_link] => 
                    [date_modified] => 2010-08-13 14:19:44
                    [content_path] => products
                )

            [SkyMax-Series] => Array
                (
                    [item] => Array
                        (
                            [content_id] => 17
                            [content_level] => 2
                            [content_left] => 25
                            [content_right] => 32
                            [content_type] => module
                            [content_url] => SkyMax-Series
                            [content_name] => SkyMax Series
                            [content_link] => 
                            [date_modified] => 2010-08-13 13:24:18
                            [content_path] => products/SkyMax-Series
                        )

                    [SkyMax-Patio-Retractable-Roof-System-1281674658] => Array
                        (
                            [item] => Array
                                (
                                    [content_id] => 0
                                    [content_name] => SkyMax Patio Retractable Roof System
                                    [content_path] => products/SkyMax-Series/SkyMax-Patio-Retractable-Roof-System-1281674658
                                    [content_item] => 1
                                    [content_level] => 3
                                    [content_left] => 25
                                    [content_right] => 32
                                    [content_type] => page
                                    [date_modified] => 2010-08-13 15:14:36
                                )

                        )

Ama bilinen nedenlerle bir daha sonra 3 düzeyleri ile çalışmaz. Herkes bu özyinelemeli yapma bazı fikirler var mı? belki kendisi, belki de çağıran bir işlevi kullanarak?

0 Cevap