FaiChan
217
4
Laravel

Array Sum

Posted 2 months ago by FaiChan

How can I sum the column of the collection in an array? eg. sum all 'kg' of collections

array:5 [▼
  0 => Collection {#796 ▼
    #items: array:1 [▼
      0 => Stock {#794 ▼
        #fillable: array:16 [▶]
        #connection: null
        #table: null
        #primaryKey: "id"
        #keyType: "int"
        +incrementing: true
        #with: []
        #perPage: 15
        +exists: true
        +wasRecentlyCreated: false
        #attributes: array:19 [▶]
        #original: array:19 [▼
          "id" => 14080
          "in_date" => "2019-02-19"
          "kg" => 0.1
          "height" => 1.0
          "width" => 1.0
          "depth" => 1.0
          "volume" => 0.0
          "location" => "a"
          "order_id" => "T201904010011"
          "out_date" => null
          "group" => 0
          "del" => 0
          "created_at" => "2019-02-19 18:46:46"
          "updated_at" => "2019-02-19 18:46:46"
        ]
        #casts: []
        #dates: []
        #dateFormat: null
        #appends: []
        #events: []
        #observables: []
        #relations: []
        #touches: []
        +timestamps: true
        #hidden: []
        #visible: []
        #guarded: array:1 [▶]
      }
    ]
  }
  1 => Collection {#832 ▼
    #items: array:1 [▶]
  }
  2 => Collection {#868 ▼
    #items: array:1 [▶]
  }
  3 => Collection {#904 ▼
    #items: array:1 [▶]
  }
  4 => Collection {#940 ▼
    #items: array:1 [▶]
  }
] 

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.