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 :: php calculate days of a month 
Php :: php has constant 
Php :: php post request 
Php :: laravel pluck relationship 
Php :: nginx 404 not found laravel 
Php :: php -S localhost:8000 
Php :: define site url wordpress 
Php :: php array sum 
Php :: insert data using model in laravel 8 
Php :: php nginx file not found 
Php :: return view with variable laravel 
Php :: php timestamp to seconds 
Php :: set postman global variable header 
Php :: php if in array 
Php :: set a minimum character value in php 
Php :: laravel without global scopes 
Php :: laravel 5 use env variable in blade 
Php :: laravel 8 decimal 
Php :: php recaptcha 
Php :: laravel migration remove nullable 
Php :: php remove control characters from string 
Php :: how to get public folder path in laravel 
Php :: get_categories not__in 
Php :: laravel npm run dev mix error FIX 
Php :: not get child all data in relationship with parent laravel eloquent 
Php :: check if file empty php 
Php :: get previous url symfony 4 in formpage 
Php :: adeleye ayodeji 
Php :: instalar php 7.4 no ubuntu 
Php :: php call class method dynamically 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =