Advertisement
ryvanyo

Función anónima que hereda valores

Feb 26th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. function contarMultiplos($numeros, $divisor){
  3.     $conta = 0;
  4.     array_walk($numeros, function($num) use($diviros, &$conta) {
  5.         if ($num % $divisor == 0) {
  6.             $conta++;
  7.         }
  8.     });
  9.     return $conta;
  10. }
  11.  
  12. $mi_arreglo = array(23, 18, 24, 66, 76, 102);
  13. echo contarMultiplos($mi_arreglo, 6);
  14. //Resultado: 4
  15. echo contarMultiplos($mi_arreglo, 2);
  16. //Resultado: 5
  17. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement