问题描述
- 关于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 ) ) ) )
)
就是让它的第三维消失 减少一维
解决方案
我的第一反应是,你的这个需求其实就很奇怪。让第三维直接消失。
我不太知道你的具体的问题是什么,为什么会有这么奇怪的想要实现的功能。
但是还是比较建议,稍微看看自己的设计是不是可以有改进的地方,很多时候,如果一个东西很丑陋,那说明还不是最佳的答案。
解决方案二:
你的需求是什麼呢?
你的數組有問題,多個2012的key放同一個數組裡面是不可能的。
时间: 2024-09-30 22:53:35