我需要一些清晰的PHP函數來實現我想要達到的目標。如何將數組子值添加到父項?
這是一個PHP數組我有:
Array
(
[0] => Array
(
[id] => 6
[index] => 1
[active] => 1
[name] => MyName
)
[1] => Array
(
[id] => 1
[index] => 2
[active] => 1
[name] => YourName
)
[2] => Array
(
[id] => 2
[index] => 4
[active] => 1
[name] => TheirName
)
}
我要採取「指數」值,使其更數組父的關鍵,因此該數組將變成這樣:
Array
(
[1] => Array
(
[id] => 6
[index] => 1
[active] => 1
[name] => MyName
)
[2] => Array
(
[id] => 1
[index] => 2
[active] => 1
[name] => YourName
)
[4] => Array
(
[id] => 2
[index] => 4
[active] => 1
[name] => TheirName
)
}
任何人都可以請告訴我如何在PHP中做到這一點?
預先感謝您。
謝謝大家3的幫助。我不確定應該將誰作爲正確的答案,所以我選擇了第一張選票。但是,你們一直對此非常有幫助!再次感謝你。 – arrayown