-1
結合不同的數組值我有一個這樣的數組:如何與公共密鑰
Array
(
[0] => Array
(
[minutesPlayed] => 0
[totalSecondsPlayed] => 0
[flagrantFouls] => 0
[foulsReceived] => 0
[blocksReceived] => 0
[plusMinus] => 0
[player] => Array
(
[playerId] => 830651
[firstName] => Walter
[lastName] => Tavares
[uniform] => 21
)
[fieldGoals] => Array
(
[made] => 0
[attempted] => 0
)
[freeThrows] => Array
(
[made] => 12
[attempted] => 4
)
[threePointFieldGoals] => Array
(
[made] => 0
[attempted] => 0
)
)
[1] => Array
(
[minutesPlayed] => 0
[totalSecondsPlayed] => 0
[flagrantFouls] => 0
[foulsReceived] => 0
[blocksReceived] => 0
[plusMinus] => 0
[player] => Array
(
[playerId] => 830651
[firstName] => John
[lastName] => Tavares
[uniform] => 22
)
[fieldGoals] => Array
(
[made] => 0
[attempted] => 0
)
[freeThrows] => Array
(
[made] => 12
[attempted] => 6
)
[threePointFieldGoals] => Array
(
[made] => 0
[attempted] => 0
)
)
[2] => Array
(
[minutesPlayed] => 0
[totalSecondsPlayed] => 0
[flagrantFouls] => 0
[foulsReceived] => 0
[blocksReceived] => 0
[plusMinus] => 0
[player] => Array
(
[playerId] => 830651
[firstName] => Adrian
[lastName] => Tavares
[uniform] => 23
)
[fieldGoals] => Array
(
[made] => 0
[attempted] => 0
)
[freeThrows] => Array
(
[made] => 0
[attempted] => 0
)
[threePointFieldGoals] => Array
(
[made] => 12
[attempted] => 8
)
)
[3] => Array
(
[minutesPlayed] => 0
[totalSecondsPlayed] => 0
[flagrantFouls] => 0
[foulsReceived] => 0
[blocksReceived] => 0
[plusMinus] => 0
[player] => Array
(
[playerId] => 830651
[firstName] => Adrian
[lastName] => Methue
[uniform] => 24
)
[fieldGoals] => Array
(
[made] => 0
[attempted] => 0
)
[freeThrows] => Array
(
[made] => 0
[attempted] => 0
)
[threePointFieldGoals] => Array
(
[made] => 0
[attempted] => 0
)
)
)
我希望它是這樣的:
Array
(
[fieldGoals] => Array
[0](
[player_name]=>Walter Tavares
[playerId] => 830651
[made] => 0
[attempted] => 0
)
[1](
[player_name]=>John Tavares
[playerId] => 830651
[made] => 0
[attempted] => 0
)
[2](
[player_name]=>Adrian Tavares
[playerId] => 830651
[made] => 0
[attempted] => 0
)
[3](
[player_name]=>Adrian Methue
[playerId] => 830651
[made] => 0
[attempted] => 0
)
[freeThrows] => Array
[0](
[player_name]=>Walter Tavares
[playerId] => 830651
[made] => 12
[attempted] => 4
)
[1](
[player_name]=>John Tavares
[playerId] => 830651
[made] => 12
[attempted] => 6
)
[2](
[player_name]=>Adrian Tavares
[playerId] => 830651
[made] => 12
[attempted] => 8
)
[3](
[player_name]=>Adrian Methue
[playerId] => 830651
[made] => 0
[attempted] => 0
)
[threePointFieldGoals] => Array
[0](
[player_name]=>Walter Tavares
[playerId] => 830651
[made] => 0
[attempted] => 0
)
[1](
[player_name]=>John Tavares
[playerId] => 830651
[made] => 0
[attempted] => 0
)
[2](
[player_name]=>Adrian Tavares
[playerId] => 830651
[made] => 0
[attempted] => 0
)
[3](
[player_name]=>Adrian Methue
[playerId] => 830651
[made] => 0
[attempted] => 0
)
)
這是我做過什麼,到目前爲止:
foreach($myArr as $playerStatsKey=>$playerStatsArray){
if(!is_array($playerStatsArray)){
continue;
}
foreach($playerStatsArray as $playkey=>$playVal){
if(!is_array($playVal)){
continue;
}
if($playkey=='player'){
$playerInfo[$playkey]['made'] = $playVal['made'];
$playerInfo[$playkey]['attempted'] = $playVal['attempted'];
}
$arr[$playkey] = $playerInfo;
$arr[$playkey] = $playVal['made'];
$arr[$playkey] = $playVal['attempted'];
}
echo '<pre>' ;print_r($arr );
我只是想結合不同的數組值與共同的key.how我可以做到這一點嗎?
使用array_merge – aldrin27
我沒有兩個不同的數組。我想根據一些關鍵字分開數組,因爲我在我的問題中詢問 – Rahul