Aims:
salary_form.html contains this form:
<form action="tax.php" method="get">
<input type="text" name="salary" value="0" />
<input type="submit" />
</form>
tax.php (next slide), which outputs the amount of tax the user must pay
at each rate
tax.php
$salary = (int) $_GET['salary'];
$tax_paid_at_lower_rate = 0.0;
$tax_paid_at_higher_rate = 0.0;
if
echo "<table>";
echo "<tr><th>Tax paid at lower rate</td><td>{$tax_paid_at_lower_rate}</td></tr>";
echo "<tr><td>Tax paid at higher rate</td><td>{$tax_paid_at_higher_rate}</td></tr>";
echo "</table>";
tax.php?
echo statements to see what gets reachedvar_dump to inspect the type and contents of variablestax.php by a programmer
who has chosen to avoid two-armed conditionals
tax.php
$salary = (int) $_GET['salary'];
$tax_paid_at_lower_rate = 0.0;
$tax_paid_at_higher_rate = 0.0;
// Determine amount of income over 20000 and tax it at the higher rate
if ( $salary > 20000 )
{
$salary_taxable_at_higher_rate = $salary - 20000;
$tax_paid_at_higher_rate = $salary_taxable_at_higher_rate * 0.2;
}
// Tax the rest at the lower rate
$tax_paid_at_lower_rate = $salary * 0.05;
echo "<table>";
echo "<tr><th>Tax paid at lower rate</td><td>{$tax_paid_at_lower_rate}</td></tr>";
echo "<tr><td>Tax paid at higher rate</td><td>{$tax_paid_at_higher_rate}</td></tr>";
echo "</table>";