fork(1) download
  1. <?php
  2.  
  3.  
  4. $employees = ['pu9me1', 'pu3me2', 'pu2an3', 'pu2ma1', 'pu1me2boss'];
  5. $regexp = '/([a-z]{2})([0-9]*)([a-z]{2})([1-3])(boss)?/';
  6. $i = 0;
  7. $x = 0;
  8. $employeesOfPurchaseDepartment = [];
  9. $matches = [];
  10.  
  11. foreach ($employees as $key => $employee) {
  12. preg_match($regexp, $employee, $matches[$i]);
  13. $bossStatus = false;
  14. if (isset($matches[$i][5])) {
  15. $bossStatus = true;
  16. }
  17. $numberOfEmployees = (int)$matches[$i][2] + $x;
  18. for ($x; $x < $numberOfEmployees; $x++) {
  19. $employeesOfPurchaseDepartment[$x] = $matches[$i][1] . $matches[$i][3] . $bossStatus . $matches[$i][4] . 400;
  20. }
  21. $i++;
  22. }
  23.  
  24. var_dump($employeesOfPurchaseDepartment);
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
array(17) {
  [0]=>
  string(8) "pume1400"
  [1]=>
  string(8) "pume1400"
  [2]=>
  string(8) "pume1400"
  [3]=>
  string(8) "pume1400"
  [4]=>
  string(8) "pume1400"
  [5]=>
  string(8) "pume1400"
  [6]=>
  string(8) "pume1400"
  [7]=>
  string(8) "pume1400"
  [8]=>
  string(8) "pume1400"
  [9]=>
  string(8) "pume2400"
  [10]=>
  string(8) "pume2400"
  [11]=>
  string(8) "pume2400"
  [12]=>
  string(8) "puan3400"
  [13]=>
  string(8) "puan3400"
  [14]=>
  string(8) "puma1400"
  [15]=>
  string(8) "puma1400"
  [16]=>
  string(9) "pume12400"
}