Answer the question
In order to leave comments, you need to log in
How to add values in php from json?
Good afternoon, tell me.
Is there a json (see below) how to sum up all "balance" values (how many will be unknown) using PHP?
{"result":{"stats":[{"balance":"0","rejected_speed":"0","accepted_speed":"0"},{"balance":"0","rejected_speed": "0","accepted_speed":"0"},
{"balance":"0.00038357","rejected_speed":"0","accepted_speed":"0"}],
At the moment I take out one at a time and add it, but this is not correct because the values can be either 1 or ten ..
$stat_data = json_decode($stat,true);
@$balance0 = $stat_data['result']['stats'][0]['balance'];
@$balance1 = $tat_data['result']['stats'][1]['balance'];
@$balance2 = $stat_data['result']['stats'][2]['balance'];
@$balance3 = $stat_data['result']['stats'][3]['balance'];
$balance = ($balance0 + $balance1 + $balance2 + $balance3);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question