title: How can I sum up values from a json string?
body: <p>I get the following json data from a database:</p>
  
  <pre><code>[{"type":"Sig","value":"0.0"},{"type":"SH","value":"9.95"},{"type":"COD","value":"6.95"}][{"type":"Sig","value":"0.0"},{"type":"SH","value":"9.95"},{"type":"COD","value":"6.95"}][{"type":"Sig","value":"0.0"},{"type":"SH","value":"9.95"},{"type":"COD","value":"6.95"}][{"type":"Sig","value":"0.0"},{"type":"SH","value":"9.95"},{"type":"COD","value":"6.95"}]
  </code></pre>
  
  <p>I'm trying to add all <code>value</code> values together, so: 9.95 + 6.95 ... so that I get 67.6 as result.</p>
  
  <p>I tried the below code, but I am getting 16.9 as repeated values.</p>
  
  <pre><code>for ($i = 0; $i &lt;= $count - 1 ; $i++) {
  
      $charge = $service[$i]['charge']; 
      $serviceValue = json_decode($charge, true); 
      $totalservice = 0;
  
      foreach ($serviceValue as $key =&gt; $value)      {              
          $totalservice += $value['service_value'];
      }
      echo $totalservice;                
  }
  </code></pre>