fork download
  1. <?php
  2.  
  3. // your code goes here
  4. function sumForArray($v1,$v2)
  5. {
  6. return array(
  7. "charm" => $v1["charm"] + $v2["charm"],
  8. "hp" => $v1["hp"] + $v2["hp"],
  9. );
  10.  
  11. }
  12.  
  13.  
  14. $strIN = '[{"charm":1,"hp":1}, {"charm":2,"hp":1}]';
  15. $arrIN = json_decode($strIN, true);
  16. print_r(array_reduce($arrIN,"sumForArray"));
Success #stdin #stdout 0.02s 24280KB
stdin
Standard input is empty
stdout
Array
(
    [charm] => 3
    [hp] => 2
)