Koledze chodziło chyba o to, by słownie wypisywało ile dany user ma lat.
Proszę, przerób sobie ten "brzydki" kod :P
public function getAge()
{
if (empty($this->birthday)) {
return 'Nie powiem';
}
$age = (new DateTime($this->birthday))->diff((new DateTime()), true)->y;
if ($age < 8) {
return 'Za młody by mieć konto';
}
if ($age > 120) {
return 'Starszy niż świat';
}
$age .= ' ' . ($age == 1 ? 'rok' : ($age % 10 >= 2 && $age % 10 <= 4 && ($age % 100 < 10 || $age % 100 >= 20) ? 'lata' : 'lat'));
return $age;
}