如何將數組的鍵轉換爲第一個元素數組? 我首選使用array_map。我有一個共同的數組。 如果我有一個這樣的數組:基於數組的第一個元素數組中的更改鍵多維
[
0 => [
'barang_id' => '7389'
'spec' => 'KCH8AT-DM'
'heat_no' => '7B4784'
'coil_no' => '0210'
'size' => '17.9'
'weight' => '2014'
'container' => 'TCLU6265556'
]
1 => [
'barang_id' => '7390'
'spec' => 'KCH8AT-DM'
'heat_no' => '7B4784'
'coil_no' => '0050'
'size' => '17.9'
'weight' => '2006'
'container' => 'TCLU6265556'
]
]
我需要這樣。第一個元素數組的值將成爲數組的關鍵字。
[
7389 => [
'barang_id' => '7389'
'spec' => 'KCH8AT-DM'
'heat_no' => '7B4784'
'coil_no' => '0210'
'size' => '17.9'
'weight' => '2014'
'container' => 'TCLU6265556'
]
7390 => [
'barang_id' => '7390'
'spec' => 'KCH8AT-DM'
'heat_no' => '7B4784'
'coil_no' => '0050'
'size' => '17.9'
'weight' => '2006'
'container' => 'TCLU6265556'
]
]
請告知
這會更簡單用普通的foreach? – marekful
@marekful是的,在我看來'foreach'會更簡單。它對我更具可讀性,它不需要參考或回調。 – Gordon