title: Laravel multidimensional array sum with collection
body: <p>My JSON output is:</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;follow_carts&quot;:[
      {
        &quot;id&quot;:1,
        &quot;user_id&quot;:10001,
        &quot;created_at&quot;:null,
        &quot;updated_at&quot;:null,
        &quot;followings&quot;:[
          {
            &quot;id&quot;:1,
            &quot;name&quot;:&quot;Dr. Timmy Kulas Sr.&quot;,
            &quot;email&quot;:&quot;sumanta.php@gmail.com&quot;,
            &quot;email_verified_at&quot;:&quot;2022-09-15T16:17:07.000000Z&quot;,
            &quot;created_at&quot;:&quot;2022-09-15T16:17:08.000000Z&quot;,
            &quot;updated_at&quot;:&quot;2022-09-15T16:17:08.000000Z&quot;,
            &quot;user_type&quot;:&quot;vendor&quot;,
            &quot;pivot&quot;:{
              &quot;follower_id&quot;:1,
              &quot;user_id&quot;:1
            },
            &quot;carts&quot;:[
              {
                &quot;id&quot;:1,
                &quot;user_id&quot;:1,
                &quot;level_two_id&quot;:1,
                &quot;cart_name&quot;:&quot;Lorem lipsum&quot;,
                &quot;main_photo&quot;:&quot;https://images.pexels.com/photos/2533311/pexels-photo-2533311.jpeg?auto=compress&amp;cs=tinysrgb&amp;w=1260&amp;h=750&amp;dpr=2&quot;,
                &quot;important_details&quot;:&quot;york&quot;,
                &quot;created_at&quot;:null,
                &quot;updated_at&quot;:null,
                &quot;status&quot;:1,
                &quot;main_category_id&quot;:1,
                &quot;opens&quot;:1
              },
              {
                &quot;id&quot;:2,
                &quot;user_id&quot;:1,
                &quot;level_two_id&quot;:2,
                &quot;cart_name&quot;:&quot;Cafe&quot;,
                &quot;main_photo&quot;:&quot;https://images.pexels.com/photos/2533311/pexels-photo-2533311.jpeg?auto=compress&amp;cs=tinysrgb&amp;w=1260&amp;h=750&amp;dpr=2&quot;,
                &quot;important_details&quot;:&quot;New York's best cafe&quot;,
                &quot;created_at&quot;:null,
                &quot;updated_at&quot;:null,
                &quot;status&quot;:0,
                &quot;main_category_id&quot;:1,
                &quot;opens&quot;:2
              }
            ]
          }
        ]
      }
    ]
  }
  </code></pre>
  <p><strong>I am trying to get total &quot;opens&quot; of all carts of each follow_carts.</strong>
  So in this case the result should be 2 + 1 = 3 opens.</p>
  <p>I want to do it using collection sum but no luck.</p>
  <p>Can anyone please give me an idea.</p>