Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel collection get price sum

$collection = collect([
    ['name' => 'Chair', 'colors' => ['Black']],
    ['name' => 'Desk', 'colors' => ['Black', 'Mahogany']],
    ['name' => 'Bookcase', 'colors' => ['Red', 'Beige', 'Brown']],
]);
 
$collection->sum(function ($product) {
    return count($product['colors']);
});
 
Comment

PREVIOUS NEXT
Code Example
Php :: docker invalid port 80 
Php :: how to test that function throws an exception in pest 
Php :: get one column in all associative array in collection laravel 
Php :: php counting number of chars excluding newlines 
Php :: zend redirect to url 
Php :: php iterate array 
Php :: cast string to int php 
Php :: php remove double spaces to single space 
Php :: date add one day php 
Php :: incorrect format parameter phpmyadmin xampp 
Php :: rtl file manager laravel 
Php :: acf get sub field 
Php :: laravel with trashed specific 
Php :: php loop through objects 
Php :: confirm password in codeigniter 
Php :: check php version 
Php :: maximum execution time of 60 seconds exceeded laravel 8 
Php :: encryp with codeigniter 3 
Php :: php hide decimals if zero 
Php :: wordpress loop 
Php :: str_replace php variable 
Php :: php variable outside foreach 
Php :: php write file 
Php :: laravel download file from public folder 
Php :: convert matrix row to column php 
Php :: create session in php 
Php :: bind in pdo 
Php :: download speed limit php 
Php :: php support block-level scope 
Php :: php check array is not associative 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =