Add up the data from php curl?

check
I get the database data of the opposite party through php curl (both parties give me json)
for example, after I take it out, I print out
a hypothetical bit

.
foreach ($xxx->{"xxx"} as $key){
   echo $key->{"xxx-price"};
}

how do I add up all $key- > {"xxx-price"} in this array ?
I know how to do mysql
but I don"t know how to add up with curl?

Mar.05,2021

<?php
$a = array(
  array(
    'id' => 5698,
    'first_name' => 'Bill',
    'last_name' => 'Gates',
  ),
  array(
    'id' => 4767,
    'first_name' => 'Steve',
    'last_name' => 'Jobs',
  ),
  array(
    'id' => 3809,
    'first_name' => 'Mark',
    'last_name' => 'Zuckerberg',
  )
);

$id = array_column($a, 'id');
print_r($id);
?>

Array
(
  [0] => 5698
  [1] => 4767
  [2] => 3809
)
array_sum($id)

14274

first: take the key, to be counted first, and then array_sum ()

$priceTotal = array_sum(array_column($xxx,'price'));

second type:

$priceTotal = 0;
foreach($xxx as $item) {
    $priceTotal += $item['price'];
}
echo $priceTotal;

depends on which one you like to use


json_decode ($json, true);

Menu