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?>
1<?php
2$indexedArray = Array(20, 20, 5.5, "str");
3$associativeArray = Array(
4 1 => 20,
5 2 => 20,
6 3 => 5.5,
7 4 => "str"
8);
9
10echo array_sum($indexedArray) . "<br>"; // 45.5
11echo array_sum($associativeArray); // 45.5
12
13?>