Aims:
2 * 3 evaluates to 62 < 3 evaluates to true2 > 3 evaluates to false| Operator | Paraphrase | Example use |
|---|---|---|
== | Equals | $a == $b |
=== | Identical | $a === $b |
!= | Not equal | $a != $b |
!== | Not identical | $a !== $b |
<> | Not equal | $a <> $b |
< | Less than | $a < $b |
> | Greater than | $a > $b |
<= | Less than or equal to | $a <= $b |
>= | Greater than or equal to | $a >= $b |
echo 2 < 3;echo 2 == 3;echo '2 == 3';$my_age = 20; $your_age = $my_age;
echo $my_age == $your_age;echo $my_age < $your_age;echo $my_age <= $your_age;
$your_age = $your_age + 1;
$is_equal = $my_age == $your_age;
echo $is_equal;$is_less_than = $my_age < $your_age;
echo $is_less_than;$is_less_than_or_equal_to = $my_age <= $your_age;
echo $is_less_than_or_equal_to;if-statement:
if ( Boolean expression )
{
zero, one or more statements
}
$my_age = 20;
$your_age = 23;
if ( $my_age < $your_age )
{
echo '<p>';
echo 'I\'m younger than you!';
echo 'The difference is ' . ($your_age - $my_age) . ' year(s).';
echo '</p>';
}
echo "<p>I am {$my_age} and you are {$your_age}.</p>";
Also, what is the output if 23 is changed to 17? What is the output if 23 is changed to 20?
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 (on the next slide), which outputs the amount of tax the user must pay on his/her salary
tax.php
$salary = (int) $_GET['salary'];
$tax = 0.0;
if
echo "<p>Your tax is {$tax} eurines</p>";
if ( $firstname == '' )
{
echo "You must supply a firstname.";
}
if ( $surname == '' )
{
echo "You must supply a surname.";
}
declaration_form.html contains this form:
<form action="duty.php" method="get">
<input type="text" name="import_value" value="0" />
<input type="text" name="days_away" value="0" />
<input type="submit" />
</form>
duty.php (on the next slide), which outputs the amount of duty the user must pay
duty.php
$import_value = (int) $_GET['import_value'];
$days_away = (int) $_GET['days_away'];
$tax_rate = 0.1;
echo "<p>You must pay {$duty} eurines</p>";