2 u012575301 u012575301 于 2014.12.01 15:36 提问

关于php减少数组维度的问题 求大神支招

Array
(
[jwc_grades] => Array
(
[0] => Array
(
[2012] => Array
(
[1] => Array
(
[term_point] => 3.5
[term_average] => 88
[grades] => Array
(
[0] => Array
(
[jwc_grade_id] => 5
[course] => 阿什顿
[point] => 2
[grade] => 1
)

                                    )

                            )

                    )

            )

        [1] => Array
            (
                [2012] => Array
                    (
                        [1] => Array
                            (
                                [term_point] => 3.5
                                [term_average] => 88
                                [grades] => Array
                                    (
                                        [0] => Array
                                            (
                                                [jwc_grade_id] => 6
                                                [course] => 是电风扇等
                                                [point] => 2
                                                [grade] => 1
                                            )

                                    )

                            )

                    )

            )

        [2] => Array
            (
                [2012] => Array
                    (
                        [2] => Array
                            (
                                [term_point] => 3.5
                                [term_average] => 88
                                [grades] => Array
                                    (
                                        [0] => Array
                                            (
                                                [jwc_grade_id] => 7
                                                [course] => 不错
                                                [point] => 2
                                                [grade] => 1
                                            )

                                    )

                            )

                    )

            )

)

如何让它变成
Array
(
[jwc_grades] => Array
(

                [2012] => Array
                    (
                        [1] => Array
                            (
                                [term_point] => 3.5
                                [term_average] => 88
                                [grades] => Array
                                    (
                                        [0] => Array
                                            (
                                                [jwc_grade_id] => 5
                                                [course] => 阿什顿
                                                [point] => 2
                                                [grade] => 1
                                            )

                                    )

                            )

                    )
                [2012] => Array
                    (
                        [1] => Array
                            (
                                [term_point] => 3.5
                                [term_average] => 88
                                [grades] => Array
                                    (
                                        [0] => Array
                                            (
                                                [jwc_grade_id] => 6
                                                [course] => 是电风扇等
                                                [point] => 2
                                                [grade] => 1
                                            )

                                    )

                            )

                    ) 
                [2012] => Array
                    (
                        [2] => Array
                            (
                                [term_point] => 3.5
                                [term_average] => 88
                                [grades] => Array
                                    (
                                        [0] => Array
                                            (
                                                [jwc_grade_id] => 7
                                                [course] => 不错
                                                [point] => 2
                                                [grade] => 1
                                            )

                                    )

                            )

                    )

)
就是让它的第三维消失 减少一维

2个回答

laiconglin
laiconglin   2014.12.05 22:05

我的第一反应是,你的这个需求其实就很奇怪。让第三维直接消失。
我不太知道你的具体的问题是什么,为什么会有这么奇怪的想要实现的功能。
但是还是比较建议,稍微看看自己的设计是不是可以有改进的地方,很多时候,如果一个东西很丑陋,那说明还不是最佳的答案。

fdipzone
fdipzone   Rxr 2014.12.18 16:47

你的需求是什麼呢?

你的數組有問題,多個2012的key放同一個數組裡面是不可能的。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!