Ver Mensaje Individual
  #4 (permalink)  
Antiguo 17/08/2016, 08:00
Avatar de hhs
hhs
Colaborador
 
Fecha de Ingreso: junio-2013
Ubicación: México
Mensajes: 2.995
Antigüedad: 10 años, 10 meses
Puntos: 379
Respuesta: funcion con parametros opcionales

Código PHP:
Ver original
  1. function sum($number, ...$numbers) {
  2.     $acc = $number;
  3.     foreach ($numbers as $n) {
  4.         $acc += $n;
  5.     }
  6.     return $acc;
  7. }
  8.  
  9. echo sum(1);
  10.  
  11. echo sum(1, 2, 3, 4);
__________________
Saludos
About me
Laraveles
A class should have only one reason to change.