Advertisement
ShadowEmbrace

Company Users

Nov 12th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.58 KB | None | 0 0
  1. <?php
  2.  
  3. $infoCompanies = [];
  4.  
  5. $cmd = explode(' -> ', readline());
  6.  
  7. while ($cmd[0] !== 'End') {
  8.     list($company, $employee) = $cmd;
  9.  
  10.     if (!key_exists($company, $infoCompanies)) {
  11.         $infoCompanies[$company] = [];
  12.     }
  13.  
  14.     if (!in_array($employee, $infoCompanies[$company])) {
  15.         $infoCompanies[$company][] = $employee;
  16.     }
  17.  
  18.     $cmd = explode(' -> ', readline());
  19. }
  20.  
  21. ksort($infoCompanies);
  22.  
  23. foreach ($infoCompanies as $companyId => $users) {
  24.     echo $companyId . PHP_EOL;
  25.     foreach ($users as $user) {
  26.         echo "-- $user" . PHP_EOL;
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement