add oop
This commit is contained in:
parent
642491a9c0
commit
9ffda1656d
4 changed files with 69 additions and 0 deletions
37
demo/oop/Frage.php
Normal file
37
demo/oop/Frage.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
readonly class Frage implements Stringable
|
||||
{
|
||||
public function __construct(
|
||||
private string $frage,
|
||||
private string $richtigeAntwort,
|
||||
private array $antworten,
|
||||
private string $frageNr,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getFrageNr(): string
|
||||
{
|
||||
return $this->frageNr;
|
||||
}
|
||||
|
||||
public function istRichtig(string $antwort): bool
|
||||
{
|
||||
return $antwort === $this->richtigeAntwort;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
$fragen = '';
|
||||
|
||||
foreach ($this->antworten as $antwort) {
|
||||
$fragen .= '<br>';
|
||||
$fragen .= sprintf('<input type="radio" name="%s" value="%s">%s</input>', $this->frageNr, $antwort, $antwort);
|
||||
}
|
||||
|
||||
$fragen .= '<hr>';
|
||||
|
||||
return $this->frage . '<br>' . $fragen;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue