0
在多維數組下面我將如何替換頂層指數[0]
[1]
& [2]
各自的價值從[SUB1]
如何用數組的項目使用PHP替換多維數組的數組?
Array
(
[0] => Array
(
[SUB1] => AAA111
[SUB2] => Description 1
[SUB3] => 10
)
[1] => Array
(
[SUB1] => BBB222
[SUB2] => Description 2
[SUB3] => 20
)
[2] => Array
(
[SUB1] => CCC333
[SUB2] => Description 3
[SUB3] => 30
)
)
我已經成功地使用$sub1 = array_column($array, 'SUB1');
得到下面的數組,但我m不知道是否存在一個簡單的函數來用它來替換原始數組中的索引值。
Array
(
[0] => AAA111
[1] => BBB222
[2] => CCC333
)
編輯:
所需的輸出:
Array
(
[AAA111] => Array
(
[SUB2] => Description 1
[SUB3] => 10
)
[BBB222] => Array
(
[SUB2] => Description 2
[SUB3] => 20
)
[CCC333] => Array
(
[SUB2] => Description 3
[SUB3] => 30
)
)
只需在一個簡單的循環中創建一個新的數組... – CBroe
顯示預期的輸出。你想怎麼樣? –
CBroe,我認爲,但我不確定大型數據集對性能的影響。 –