title: PHP JSON Count values in same array
body: <p>I have a json object in my php script that was encoded using the <code>json_encode</code> php function.</p>
  
  <p>Here is the object when var_dumped...</p>
  
  <pre><code>string '{"voting_sys":"50","beta_site":"50"}' (length=36)
  string '{"voting_sys":"50","beta_site":"50"}' (length=36)
  </code></pre>
  
  <p>Database structure: <img src="https://i.stack.imgur.com/l15kn.png" alt="Database Structure"></p>
  
  <p>My goal is to get the sum of the values in the voting_sys for each user, and in the beta_site...this is going to be used for voting, but on an unknown amount of features/values.</p>
  
  <p>Any ideas? I have tried the following...</p>
  
  <pre><code>$voters = DB::table('votes')-&gt;get();
      foreach($voters as $vote){
              $vote_array[$voter-&gt;user_id]=json_decode($voter-&gt;value, true);
      }
      var_dump($vote_array);
  </code></pre>
  
  <p>This returns the decoded json object to the array.
  I would assign the "voting_sys" as the key for the array, and then the integer value to the value of the array, but there will be an unknown number of features. In this example, there are only two features the users can vote on, but there may be more at a later date. I use the feature ID to roll out a new set of features the users can vote on.</p>
  
  <p>I am using Laravel 4.1</p>
  
  <p>[Edit: Result]</p>
  
  <pre><code>    $feature_list = DB::table('features')-&gt;where('rev_id', Config::get('app.beta_rev'))-&gt;get();
      $feature_array=array();
      foreach ($feature_list as $feature){
          array_push($feature_array, $feature-&gt;name);
      }
      foreach($feature_array as $feature){
          $voters = DB::table('votes')
                   -&gt;select(DB::raw('sum(value)'))
                   -&gt;where('feature_name', '=', $feature)
                   -&gt;get();
                   echo $feature.' - ';
                   var_dump($voters);
                   echo '&lt;br /&gt;';
      }
  </code></pre>
  
  <p>which when called, dumps:</p>
  
  <pre><code>voting_sys -
  array (size=1)
    0 =&gt; 
      object(stdClass)[248]
        public 'sum(value)' =&gt; string '149' (length=3)
  
  beta_site -
  array (size=1)
    0 =&gt; 
      object(stdClass)[249]
        public 'sum(value)' =&gt; string '69' (length=2)
  </code></pre>
  
  <p>Which is exactly correct for the votes I entered. Thanks for the help.</p>