fork download
  1. <?php
  2.  
  3. $array = [1, 2, 3, 4, 5];
  4. $factor = 2;
  5.  
  6. function multiplica($array) {
  7.  
  8. $factor = 5;
  9.  
  10. $array = array_map(function ($value) {
  11. global $factor;
  12. return $value * $factor;
  13. }, $array);
  14.  
  15. return $array;
  16.  
  17. }
  18.  
  19. print_r(multiplica($array));
Success #stdin #stdout 0.01s 82880KB
stdin
Standard input is empty
stdout
Array
(
    [0] => 2
    [1] => 4
    [2] => 6
    [3] => 8
    [4] => 10
)