array sum in multidimensional array php

Solutions on MaxInterview for array sum in multidimensional array php by the best coders in the world

showing results for - "array sum in multidimensional array php"
María Paula
17 Mar 2020
1<?php
2$items = [
3    ['label' => 'cake', 'name' => 'Cake', 'price' => 150],
4    ['label' => 'pizza', 'name' => 'Pizza', 'price' => 250],
5    ['label' => 'puff', 'name' => 'Veg Puff', 'price' => 20],
6    ['label' => 'samosa', 'name' => 'Samosa', 'price' => 14]
7];
8
9$arrSum = array_sum(array_column($items, 'price', 'name'));
10print "Sum of Array : ".$arrSum."<br/>";
11?>
12
Leanne
30 May 2016
1<?php
2
3$items = [
4    ['label' => 'cake', 'name' => 'Cake', 'price' => 150],
5    ['label' => 'pizza', 'name' => 'Pizza', 'price' => 250],
6    ['label' => 'puff', 'name' => 'Veg Puff', 'price' => 20],
7    ['label' => 'samosa', 'name' => 'Samosa', 'price' => 14]
8];
9
10$arrSum = array_sum(array_column($items, 'price', 'name'));
11print "Sum of Array : ".$arrSum."<br/>";
12?>