PHP code example of outcloud / php-array-avg-callable

1. Go to this page and download the library: Download outcloud/php-array-avg-callable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

outcloud / php-array-avg-callable example snippets


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

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

array_avg_callable($items, function($item){
    return $item->getValue();
});
bash
composer