如何安排這個陣列由最後內索引(0,1,2),並獲得最後的內側索引的值作爲每個第二指標的值:排列PHP多維數組通過內側索引
Array
(
[text] => Array
(
[grid] => Array
(
[0] => 3
[1] => 4
[2] => 5
)
[image] => Array
(
[0] =>
[1] =>
[2] =>
)
[align] => Array
(
[0] => left
[1] => right
[2] => left
)
[title] => Array
(
[0] =>
[1] =>
[2] =>
)
[content] => Array
(
[0] =>
[1] =>
[2] =>
)
)
)
並得到如下結果:
Array
(
[text] => Array
(
[0] => Array
(
[grid] => 3
[image] =>
[align] => left
[title] =>
[content] =>
)
[1] => Array
(
[grid] => 4
[image] =>
[align] => right
[title] =>
[content] =>
)
[2] => Array
(
[grid] => 5
[image] =>
[align] => left
[title] =>
[content] =>
)
)
)
你尋找一個班輪解決方案嗎?可以肯定的是,上面的使用'foreach'是微不足道的。 – 2012-07-27 07:21:08
你的解決方案中的索引[0]在哪裏?你只掃描1和2. 這些問題可以很容易地通過創建一個新的結果數組和foreach($ someArr作爲$ key => $ value)來解決 – 2012-07-27 07:25:37
@SiGanteng我在尋找更好的方式來安排每個第一個數組通過其子索引。上面的例子使用0,1和2索引。最後一個子索引從0開始到任意數字。 – zourbuth 2012-07-27 07:26:44