fork download
  1. <?php
  2.  
  3. $calls = [
  4. ['prefix' => '+57'],
  5. ['prefix' => '+268'],
  6. ['prefix' => '+972'],
  7. ['prefix' => '+972'],
  8. ['prefix' => '+33'],
  9. ['prefix' => '+33'],
  10. ['prefix' => '+972'],
  11. ['prefix' => '+509'],
  12. ['prefix' => ''],
  13. ['prefix' => '+33'],
  14. ['prefix' => '+268'],
  15. ['prefix' => '+57'],
  16. ];
  17.  
  18.  
  19. $result = array_reduce($calls, myStatCounter, []);
  20.  
  21. print_r($result);
  22.  
  23. function myStatCounter($stat, $call) {
  24. $prefix = $call['prefix'];
  25. if (empty($stat[$prefix])) $stat[$prefix] = 0;
  26. $stat[$prefix]++;
  27. return $stat;
  28. }
  29.  
  30.  
Success #stdin #stdout #stderr 0.01s 82560KB
stdin
Standard input is empty
stdout
Array
(
    [+57] => 2
    [+268] => 2
    [+972] => 3
    [+33] => 3
    [+509] => 1
    [] => 1
)
stderr
PHP Notice:  Use of undefined constant myStatCounter - assumed 'myStatCounter' in /home/oVEXWa/prog.php on line 19