Aims:
if-else
)if-else
-statement:
if ( Boolean expression )
{
zero, one or more statements
}
else
{
zero, one or more statements
}
$grade = 57; if ( $grade < 40 ) { echo '<p>You have failed your degree.</p>'; } else { echo '<p>You have passed your degree.</p>'; } echo '<p>Goodbye!</p>';
Also, what is the output if 57 is changed to 12?
if ( $sex == 'F' ) { echo '<p>Hello sir</p>'; }; else { echo '<p>Hello madam</p>'; }
if
s instead of an
if-else
$grade = 57; if ( $grade < 40 ) { echo '<p>You have failed your degree.</p>'; } if ( $grade >= 40 ) { echo '<p>You have passed your degree.</p>'; } echo '<p>Goodbye!</p>';
$cont = (int) $_GET['cont']; $exam = (int) $_GET['exam']; $message = '<p>You have failed</p>'; if ( $cont >= 40 && $exam >= 40 ) { $message = '<p>You have passed</p>'; } echo $message;
$cont = (int) $_GET['cont']; $exam = (int) $_GET['exam']; $message = ''; if else echo $message;
gas.html
contains this form:
<form action="gas.php" method="get"> <input type="radio" name="tariff" value="A" /> <input type="radio" name="tariff" value="B" /> <input type="text" name="units" value="0" /> <input type="submit" /> </form>
gas.php
(next slide), which outputs the customer's bill
gas.php
$tariff = $_GET['tariff']; $units = (int) $_GET['units']; $fixed_charge = 0.0; $variable_rate = 0.0; $total_charge = 0.0; // Set the fixed charge and variable rate, depending on the tariff if // If high consumption, add energy tax if echo "<p>Pay us {$total_charge}, or we'll send the boys round</p>";