How can the issue of displaying 0, -1, -2 instead of "Abgelaufen" when the time period has expired be resolved in the code?
The issue can be resolved by checking if the time period has expired and displaying 0, -1, or -2 instead of "Abgelaufen" accordingly. This can be achieved by using an if-else statement to determine the appropriate value to display based on the expiration status.
<?php
// Assuming $timeLeft contains the time left in seconds
if ($timeLeft <= 0) {
if ($timeLeft == 0) {
echo "0";
} elseif ($timeLeft == -1) {
echo "-1";
} else {
echo "-2";
}
} else {
echo "Noch gültig";
}
?>