Shortened Code for Saving Default Values in PHP
The code we got is very long. Let's
shorten it. First, instead of if,
let's use the ternary operator:
<form action="" method="GET">
<input
name="test"
value="<?php
echo isset($_GET['test']) ? $_GET['test'] : 'default'
?>"
>
<input type="submit">
</form>
And now let's use the shortened PHP tag syntax:
<form action="" method="GET">
<input
name="test"
value="<?= isset($_GET['test']) ? $_GET['test'] : 'default' ?>"
>
<input type="submit">
</form>
And now let's use the ?? operator, which
will shorten the code even more:
<form action="" method="GET">
<input name="test" value="<?= $_GET['test'] ?? 'default' ?>">
<input type="submit">
</form>
Using three inputs, ask the user for the year, month, and day. After submitting the form, display how many days are left from the entered date until the New Year. Upon visiting the page, make sure the inputs display the current date.