Php 重新排列数组索引

Php 重新排列数组索引,php,arrays,multidimensional-array,indexing,Php,Arrays,Multidimensional Array,Indexing,我有一个多维数组,如下所示 Array ( [0] => attributewidget Object ( [_child] => Array ( ) [_parent] => [_oid] => a_1 [_e

我有一个多维数组,如下所示

  Array
    (
        [0] => attributewidget Object
            (
                [_child] => Array
                    (
                    )

                [_parent] => 
                [_oid] => a_1
                [_errorMsg] => 
                [_debugTraceFunc] => 
                [classname] => AttributeWidget
                [version] => 1.0.0.0
                [attributeName] => 
                [comparableProperties] => Array
                    (
                        [0] => abbreviation
                        [1] => attributeName
                        [2] => classname
                        [3] => conditionRef
                    )

            )

        [1] => Array
            (
                [0] => attributewidget Object
                    (
                        [_child] => Array
                            (
                            )

                        [_parent] => 
                        [_oid] => a_2
                        [_errorMsg] => 
                        [_debugTraceFunc] => 
                        [classname] => AttributeWidget
                        [version] => 1.0.0.0
                        [attributeName] => 
                        [comparableProperties] => Array
                            (
                                [0] => abbreviation
                                [1] => attributeName
                                [2] => classname
                                [3] => conditionRef
                            )

                    )

            )
        [2] => Array
        (
            [0] => attributewidget Object
                (
                    [_child] => Array
                        (
                        )

                    [_parent] => 
                    [_oid] => a_3
                    [_errorMsg] => 
                    [_debugTraceFunc] => 
                    [classname] => AttributeWidget
                    [version] => 1.0.0.0
                    [attributeName] => cp1
                    [comparableProperties] => Array
                        (
                            [0] => abbreviation
                            [1] => attributeName
                            [2] => classname
                            [3] => conditionRef
                        )

                )

        )
    )
理想情况下,我希望删除[1]=>Array[2]=>Array并重新排列索引。 是否有一种方法可以将索引重新排列如下

 Array
    (
        [0] => attributewidget Object
            (
                [_child] => Array
                    (
                    )

                [_parent] => 
                [_oid] => a_1
                [_errorMsg] => 
                [_debugTraceFunc] => 
                [classname] => AttributeWidget
                [version] => 1.0.0.0
                [attributeName] => 
                [comparableProperties] => Array
                    (
                        [0] => abbreviation
                        [1] => attributeName
                        [2] => classname
                        [3] => conditionRef
                    )

            )

                [1] => attributewidget Object
                    (
                        [_child] => Array
                            (
                            )

                        [_parent] => 
                        [_oid] => a_2
                        [_errorMsg] => 
                        [_debugTraceFunc] => 
                        [classname] => AttributeWidget
                        [version] => 1.0.0.0
                        [attributeName] => Name?
                        [comparableProperties] => Array
                            (
                                [0] => abbreviation
                                [1] => attributeName
                                [2] => classname
                                [3] => conditionRef
                            )

                    )



            [2] => attributewidget Object
                (
                    [_child] => Array
                        (
                        )

                    [_parent] => 
                    [_oid] => a_3
                    [_errorMsg] => 
                    [_debugTraceFunc] => 
                    [classname] => AttributeWidget
                    [version] => 1.0.0.0
                    [attributeName] => cp1
                    [comparableProperties] => Array
                        (
                            [0] => abbreviation
                            [1] => attributeName
                            [2] => classname
                            [3] => conditionRef
                        )

                )


    )

循环遍历数组,并用第一个元素替换嵌套数组中的任何元素,以移除额外的间接级别

foreach ($array as &$element) {
    if (is_array($element) {
        $element = $element[0];
    }
}

这个数组是如何创建的如此不一致?为什么[0]直接指向一个对象,而[1]和[2]中有一个额外的数组?也许您应该首先修复创建数组的代码,这样它就不会这样做了。Pro发布提示:。