I am retrieving JSON data in array and I sort them into the HTML table. So far it is OK, but I would like to sum the specific values from JSON Response and print the sum of object values.
I have a PHP code which sorting me the data from JSON as following:
foreach($result->response as $value)
{
echo "<tr>";
echo "<td>" . $value->datetime . "</td>";
echo "<td>" . $value->service_type . "</td>";
echo "<td>" . $value->destination . "</td>";
echo "<td>" . $value->duration . "</td>";
echo "<td>" . $value->price . "</td>";
echo "</tr>";
}
I am interested only in values of prices (in JSON Array), I would like to take only the value of prices from JSON and sum the values of prices and give the result number under the table.
I am trying this without any success:
$countprice = $result->response->price;
$totalprice = count($countprice);
echo $totalprice;
The result is weird number, I know that PHP use "count", but I am not sure how to use it. Sorry I am novice in JSON and PHP and I will thank you for any tip you may give me.
SUMof price?$result->responsea JSON ?