Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. <?php
  2.  
  3. class Person
  4. {
  5.     private $name;
  6.     private $age;
  7.  
  8.     public function __construct(string $name, int $age)
  9.     {
  10.         $this->name = $name;
  11.         $this->age = $age;
  12.     }
  13.  
  14.     public function getName():string
  15.     {
  16.         return $this->name;
  17.     }
  18.  
  19.     public function getAge():int
  20.     {
  21.         return $this->age;
  22.     }
  23. }
  24.  
  25. $counter = trim(fgets(STDIN));
  26. for ($i = 0; $i < $counter; $i++) {
  27.     $inputs = trim(fgets(STDIN));
  28.     $input = explode(" ", $inputs);
  29.  
  30.     $persons[] = new Person($input[0], intval($input[1]));
  31. }
  32. function sortAlphabetically(Person $a, Person $b)
  33. {
  34.     return $a->getName() <=> $b->getName();
  35. }
  36.  
  37. usort($persons, "sortAlphabetically");
  38.  
  39. foreach ($persons as $person) {
  40.     if ($person->getAge() > 30) {
  41.         echo $person->getName() . " - " . $person->getAge() . "\n";
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement