我有一個一維數組,如下所示。 (它可以動態地擴展到任何長度)如何將一個數組拆分爲3個數組
Array
(
[0] => Array
(
[city] => Trivandrum
[citykey] => ab5416c6
)
[1] => Array
(
[city] => Kochi
[citykey] => 85cb7d9c
)
[2] => Array
(
[city] => Alappuzha
[citykey] => 4d5f200e
)
[3] => Array
(
[city] => Mumbai
[citykey] => 47d98024
)
)
現在我想將它分成3個數組。我的意思是我想將一個數組分割成3個數組,如下所示。
Array
(
[0] => Array
(
[city] => Trivandrum
[citykey] => ab5416c6
)
[1] => Array
(
[city] => Mumbai
[citykey] => 47d98024
)
)
Array
(
[0] => Array
(
[city] => Kochi
[citykey] => 85cb7d9c
)
)
Array
(
[0] => Array
(
[city] => Alappuzha
[citykey] => 4d5f200e
)
)
取決於你如何想它分爲3個不同的陣列,[array_chunk( )](http://www.php.net/manual/en/function.array-chunk.php)可能會有所幫助。 – drew010 2012-04-28 17:14:30
你想要每個數組包含什麼?這個問題並不清楚。你能否提供這個四元素數組的預期輸出? – 2012-04-28 17:15:14
我想得到這個輸出。陣列 ( [0] =>數組 ( [城市] =>特里凡德琅 [citykey] => ab5416c6 ) [1] =>數組 ( [城市] =>孟買 [citykey] => 47d98024 ) ) 陣列 ( [0] =>數組 ( [城市] =>高知 [citykey] => 85cb7d9c ) ) 陣列 ( [0] =>陣列 ( [城市] =>阿拉普扎 [citykey] => 4d5f200e ) ) – Sunil 2012-04-28 17:19:16