我有一個數組,看起來像這樣:PHP陣列重新安排
array(3) {
["title"]=>
array(3) {
[0]=>
string(3) "one"
[1]=>
string(3) "two"
[2]=>
string(4) "test"
}
["file"]=>
array(3) {
[0]=>
string(25) "company_handbook_2011.pdf"
[1]=>
string(8) "test.doc"
[2]=>
string(8) "test.doc"
}
["status"]=>
array(3) {
[0]=>
string(4) "SHOW"
[1]=>
string(4) "HIDE"
[2]=>
string(4) "HIDE"
}
}
我怎麼可以重新安排它看起來像這樣:
array(
array(
"one",
"company_handbook_2011.pdf",
"SHOW"
),
array(
"two",
"test.doc",
"HIDE"
),
array(
"test",
"test.doc",
"HIDE"
),
)
即得到各的第一要素數組和和構建一個新的數組,然後第二個元素等。非常感謝您的幫助。
對此,我認爲沒有現成的功能。你必須簡單地遍歷循環中的數組,然後構建它 – 2011-04-07 15:41:30
由於索引似乎在不同的鍵之間匹配,所以您不必遍歷數組。你可以統計數字'$ array ['title']',然後使用一個簡單的for循環從正確的位置獲取值來構造一個新的數組。基準測試哪種方法更快會很有趣。 – Capsule 2011-04-07 15:44:43
非常感謝你們提供的一些有用的信息...非常感謝你的時間。 array_map完成了這項工作。 – bharath 2011-04-07 15:56:24