Advertisement
Guest User

Company users

a guest
Mar 25th, 2019
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. <?php
  2. $input = readline();
  3. $company = [];
  4. while (true) {
  5. if ($input == "End") {
  6. break;
  7. }
  8. $args = explode(" -> ", $input);
  9. $companyName = $args[0];
  10. $employeeID = $args[1];
  11. if (!key_exists($employeeID, $company)) {
  12. $company[$companyName][] = $employeeID;
  13. }
  14. $input = readline();
  15. }
  16.  
  17. uksort($company, function ($id1, $id2) use ($company) {
  18. $count1 = count($company[$id2]);
  19. $count2 = count($company[$id1]);
  20. if ($count1 === $count2) {
  21. return $count1 <=> $count2;
  22. }
  23. return $count2 <=> $count1;
  24. });
  25. foreach ($company as $key => $value) {
  26. asort($value);
  27. $count = count($value);
  28. echo $key . PHP_EOL;
  29. foreach ($value as $id) {
  30. echo "-- " . $id . PHP_EOL;
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement