Created
July 17, 2019 23:53
-
-
Save parzibyte/d86f948ebd1736bed53302e0efac0336 to your computer and use it in GitHub Desktop.
Promedio de arreglo en PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// https://parzibyte.me/blog | |
$numeros = array(12, 34, 554, 123); | |
$suma = 0; | |
foreach ($numeros as $numero) { | |
$suma += $numero; | |
} | |
// Obtener longitud | |
$cantidadDeElementos = count($numeros); | |
// Dividir, y listo | |
$promedio = $suma / $cantidadDeElementos; | |
echo "Promedio: $promedio"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment