outcloud/php-array-sum-callable 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

outcloud/php-array-sum-callable

Composer 安装命令:

composer require outcloud/php-array-sum-callable

包简介

Calculates sum of elements of array given by callback function

README 文档

README

Sums array of objects/numbets via callable function

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.

Let's this be our class

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

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

Let's use array_sum_callable to calculate sum of that numbers

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

Result will of course be: 6

Return Values

Returns the sum of values as an integer or float; 0 if the array is empty.

Installation

via Composer:

composer require outcloud/php-array-sum-callable

function will be registered in global namespace.

统计信息

  • 总下载量: 16
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-11-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固