title: How to sum data in array of JSON that get from controller when we compact to the view (Laravel)
body: <p>I am facing an issue. In the JSON array given below:</p>
  <pre><code>$results = [
  { 
      proj_name: rental,
      act_name: income,
      amount: &quot;1000&quot;
  },
  {
      proj_name: rental,
      act_name: expend,
      amount: &quot;-2000&quot;
  },
  {
      proj_name: rental,
      act_name: initiall,
      amount: &quot;3000&quot;
  },
  {
      proj_name: rental,
      act_name: income,
      amount: &quot;4000&quot;
  },
  {
      proj_name: rental,
      act_name: expend,
      amount: &quot;-5000&quot;
  },
  {
      proj_name: rental,
      act_name: initial,
      amount:&quot;6000&quot;
  },
  { 
      proj_name: loan,
      act_name: income,
      amount: &quot;7000&quot;
  },
  {
      proj_name: loan,
      act_name: expend,
      amount: &quot;-8000&quot;
  },
  {
      proj_name: loan,
      act_name: initial,
      amount: &quot;9000&quot;
  },
  {
      proj_name: loan,
      act_name: income,
      amount: &quot;10000&quot;
  },
  {
      proj_name: loan,
      act_name: expend,
      amount: &quot;-11000&quot;
  },
  {
      proj_name: loan,
      act_name: initial,
      amount:&quot;12000&quot;
  }
  ]
  </code></pre>
  <p>We can see here we have two <code>proj_name</code> as <code>rental</code> and <code>loan</code>.</p>
  <p>Also transactions are categorized further with in 3 activities as <code>income</code>, <code>expend</code> and <code>initial</code>.</p>
  <p>My question is how i can loop through <code>$results</code> array to calculate sum for each transaction type that i listed above. I would like the output to be like this:</p>
  <pre class="lang-none prettyprint-override"><code>|------------------|
  |      rental      |
  |------------------|
  |income : 5000     |
  |expend : -7000    |
  |initial : 9000    |
  |------------------|
  |Sum Rental: 7000  |
  |------------------|
  |
  |------------------|
  |      loan        |
  |------------------|
  |income : 17000    |
  |expend : -19000   |
  |initial : 21000   |
  |------------------|
  |Sum Loan: 19000   |
  |------------------|
  </code></pre>