Signatur
if (bool $condition) { … } elseif (bool $condition) { … } else { … }
Beschreibung
PHP unterstützt zwei Syntax-Varianten: geschweifte Klammern (Standard) und die alternative Syntax mit if: ... endif, die in Templates lesbarer ist.
Rückgabewert
Typ
void
Beispiele
Standard
<?php
if ($alter >= 18) {
echo 'volljährig';
} elseif ($alter >= 14) {
echo 'strafmündig';
} else {
echo 'kind';
}
Template-Syntax
<?php if ($user->isAdmin()): ?>
<a href="/admin">Admin</a>
<?php endif; ?>