PHP - array_sum
Trieda
Metóda - array_sum
(PHP 4 >= 4.0.4, PHP 5, PHP 7)
Returns the sum of all values in an array. Keys do not matter. The function is useful e.g. for calculating an arithmetic mean. It tries to convert string values in the array to numbers using standard conversion.
Procedurálne
- function array_sum (array $array) : number
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| $array | array | An array containing |
Mávratovej hodnoty
Vracia: number
The sum of all values in the array.
Príklady
<?php
$grades =[1, 2, 2, 3, 4, 5];
$average = array_sum($grades) / count($grades);
echo ("An average grade: {$average}");
