Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created July 17, 2019 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/d86f948ebd1736bed53302e0efac0336 to your computer and use it in GitHub Desktop.
Save parzibyte/d86f948ebd1736bed53302e0efac0336 to your computer and use it in GitHub Desktop.
Promedio de arreglo en PHP
<?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