2017 © Pedro Peláez
 

library php-array-sum-callable

Calculates sum of elements of array given by callback function

image

outcloud/php-array-sum-callable

Calculates sum of elements of array given by callback function

  • Tuesday, November 14, 2017
  • by Macintoshx
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

php_array_sum_callable

Sums array of objects/numbets via callable function, (*1)

Example usage:

Let's assume we have any object of any class with some numeric value inside. We have an array of that objects, and we have to calculate a sum of those numeric values., (*2)

Let's this be our class, (*3)

class Num{
    private $value;

    public function __construct(int $number){
        $this->value = $number;
    }
    public function getValue(){
        return $this->value;
    }
}

we have array of items of 'Num' class, (*4)

$items = [
    new Num(1),
    new Num(2),
    new Num(3),
];

Let's use array_sum_callable to calculate sum of that numbers, (*5)

array_sum_callable($items, function($item){
    return $item->getValue();
});

Result will of course be: 6, (*6)

Return Values

Returns the sum of values as an integer or float; 0 if the array is empty., (*7)

Installation

via Composer:, (*8)

composer require outcloud/php-array-sum-callable

function will be registered in global namespace., (*9)

The Versions

14/11 2017

dev-master

9999999-dev

Calculates sum of elements of array given by callback function

  Sources   Download

MIT

The Requires

 

by Grzegorz Lieske

14/11 2017

1.0.1

1.0.1.0

Calculates sum of elements of array given by callback function

  Sources   Download

MIT

The Requires

 

by Grzegorz Lieske

13/11 2017

1.0.0

1.0.0.0

Calculates sum of elements of array given by callback function

  Sources   Download

MIT

The Requires

 

by Grzegorz Lieske