使用PHP中的子元素(元素)从平面数组创建嵌套数组

时间:2014-10-14 20:11:34

标签: php arrays

是否可以转换元素数组:

Array
(
[@attributes] => Array
    (
        [targetNamespace] => http://example.com
    )

[element] => Array
    (
        [0] => Array
            (
                [@attributes] => Array
                    (
                        [name] => title
                        [type] => string
                    )

            )

        [1] => Array
            (
                [@attributes] => Array
                    (
                        [name] => author
                        [type] => string
                    )

            )

        [2] => Array
            (
                [@attributes] => Array
                    (
                        [name] => book
                    )

                [complexType] => Array
                    (
                        [sequence] => Array
                            (
                                [element] => Array
                                    (
                                        [0] => Array
                                            (
                                                [@attributes] => Array
                                                    (
                                                        [ref] => namespace:title
                                                    )

                                            )

                                        [1] => Array
                                            (
                                                [@attributes] => Array
                                                    (
                                                        [ref] => namespace:author
                                                    )

                                            )

                                    )

                            )

                    )

            )

    )

)

我们可以从"元素"在这种情况下的关键

基于子元素名称的嵌套数组:

Array
(
[book] => Array
    (
        [element] => Array
            (
                [0] => Array
                    (
                        [@attributes] => Array
                            (
                                [ref] => namespace:title
                                [name] => title
                            )

                    )

                [1] => Array
                    (
                        [@attributes] => Array
                            (
                                [ref] => namespace:author
                                [name] => author
                            )

                    )

            )

    )

)

这是xsd文件的表示,我试图在模式中找到rootElement

0 个答案:

没有答案