我想了解PHP數組方法,所以Id更喜歡使用數組方法來解決此問題。用於使用不同的數組值替換內部數組值的方法具有相同的密鑰
這裏是我的數據:
$dataA =>
array
0 =>
array
'type' => string 'name' (length=4)
'key' => string 'keywords' (length=8)
'content' => string 'keywordA' (length=14)
$dataB =>
array
1 =>
array
'type' => string 'name' (length=4)
'key' => string 'keywords' (length=8)
'content' => string 'keywordB' (length=14)
我想要做的是有兩個數組合並,並最終content
關鍵是:
$finalData =>
array
0 =>
array
'type' => string 'name' (length=4)
'key' => string 'keywords' (length=8)
'content' => string 'keywordB' (length=14)
^-- notice here that the content has changed based on the fact that 'key' for both is 'keywords'
正如你所看到的,最終的內容值來自$ dataB。
是否陣列a或b包含具有相同'key'多個元素?你需要數字指標在任何地方保存嗎? –
現在來看看。我之前投票結束這個問題,因爲它沒有正確的措辭,所以如果它沒有對不起。 – jkushner
該編輯不回答我的任何問題。我提供的解決方案假定唯一的鍵值並且不需要數字索引。 –