Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. <?php
  2.  
  3. class Person {
  4.  
  5. private $name;
  6. private $age;
  7. private $occupation;
  8.  
  9.  
  10. public function __construct(string $name, int $age, string $occupation)
  11. {
  12. $this->name = $name;
  13. $this->age = $age;
  14. $this->occupation = $occupation;
  15. }
  16.  
  17.  
  18. }
  19.  
  20. $persons = [];
  21. $occupations = [];
  22.  
  23. while (true){
  24. $line = explode(' ', trim(fgets(STDIN)));
  25. if ($line[0] == 'END'){
  26. break;
  27. }
  28.  
  29. $name = $line[0];
  30. $age = intval($line[1]);
  31. $occupation = $line[2];
  32.  
  33.  
  34. $person = new Person($name, $age, $occupation);
  35.  
  36. $persons[$name] = $age;
  37. $occupations[$name] = $occupation;
  38. }
  39.  
  40. $count = 0;
  41. asort($persons);
  42. foreach ($persons as $name => $age){
  43. echo $name . ' - age: ' . $age . ', occupation: ' . $occupations[$name] . "\r\n";
  44. $count++;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement