我有一個JSON字符串與球員的統計數據,我想總的球員得分在這裏,玩家名稱是JSON如何計算球員得分與PHP
<code>{
"Players": [
{
"playerId": 1,
"player_name": "Player 1",
"player_score": 10
"game_type": "action"
},
{
"playerId": 2,
"player_name": "Player 1",
"player_score": 120
"game_type": "action"
},
{
"playerId": 1,
"player_name": "Player 1",
"player_score": 233
"game_type": "action"
},
{
"playerId": "n",
"player_name": "Player n",
"player_score": "n"
}
]
}
</code>
的例子。在這個例子中,我需要例如找到玩家1並計算所有點數 所以這就是它應該是正確的玩家1有233點+10點= 243點,$ player_name => $ totalpoints;
我試着用循環來做到這一點,但沒有成功。
到目前爲止,您嘗試了什麼?另外,恕我直言,把它留到後端可能會更好。爲了有所幫助,在數組上使用'each' –
使用'json_decode'然後運行一個循環..很可能 – adelowo