Search
 
SCRIPT & CODE EXAMPLE
 

PHP

array_sum in multidimensional array php

<?php
$items = [
    ['label' => 'cake', 'name' => 'Cake', 'price' => 150],
    ['label' => 'pizza', 'name' => 'Pizza', 'price' => 250],
    ['label' => 'puff', 'name' => 'Veg Puff', 'price' => 20],
    ['label' => 'samosa', 'name' => 'Samosa', 'price' => 14]
];

$arrSum = array_sum(array_column($items, 'price', 'name'));
print "Sum of Array : ".$arrSum."<br/>";
?>
Comment

sum of multidimensional array in php

<?php

$items = [
    ['label' => 'cake', 'name' => 'Cake', 'price' => 150],
    ['label' => 'pizza', 'name' => 'Pizza', 'price' => 250],
    ['label' => 'puff', 'name' => 'Veg Puff', 'price' => 20],
    ['label' => 'samosa', 'name' => 'Samosa', 'price' => 14]
];

$arrSum = array_sum(array_column($items, 'price', 'name'));
print "Sum of Array : ".$arrSum."<br/>";
?>
Comment

PREVIOUS NEXT
Code Example
Php :: hide php extension htaccess 
Php :: laravel carbon time format AM PM 
Php :: how to populate dropdown list with array values in php 
Php :: php get elapsed time 
Php :: image upload form 
Php :: php array remove empty values 
Php :: last insert id model codeigniter 
Php :: php get current datetime mysql format 
Php :: date casting from datetime to d-m-Y laravel using cast 
Php :: mac use php@7.4 
Php :: remove http / https from link php 
Php :: check the php version in ubuntu 
Php :: migrate specific migration laravel 
Php :: laravel module create controller 
Php :: laravel Route::group definition 
Php :: check if a string contains a substring php 
Php :: foreach empty laravel 
Php :: laravel https assets 
Php :: There is no existing directory at "/var/www/storage/logs" and it could not be created: Permission denied 
Php :: write if and else in one line php 
Php :: php get url path name 
Php :: session has laravel blade 
Php :: home url wordpress 
Php :: php request uri 
Php :: hashing passwords in yii 1 
Php :: previous url laravel 
Php :: first day of month php 
Php :: form validation nullable laravel 
Php :: laravel carbon count days between dates 
Php :: laravel collection shuffle 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =