Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Person
- {
- private $name;
- private $age;
- public function __construct(string $name, int $age)
- {
- $this->name = $name;
- $this->age = $age;
- }
- public function getName():string
- {
- return $this->name;
- }
- public function getAge():int
- {
- return $this->age;
- }
- }
- $counter = trim(fgets(STDIN));
- for ($i = 0; $i < $counter; $i++) {
- $inputs = trim(fgets(STDIN));
- $input = explode(" ", $inputs);
- $persons[] = new Person($input[0], intval($input[1]));
- }
- function sortAlphabetically(Person $a, Person $b)
- {
- return $a->getName() <=> $b->getName();
- }
- usort($persons, "sortAlphabetically");
- foreach ($persons as $person) {
- if ($person->getAge() > 30) {
- echo $person->getName() . " - " . $person->getAge() . "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement