Aims:
$x
contains 2,
$y
contains 4 and $z
contains 6?
if ( $x > 1 && $y == 4 ) { $z = $z / $x; } if ( $x < 2 || $z == 3 ) { $z = $z + 1; } echo $z;
$x
contains 3,
$y
contains 5 and $z
contains 3?
if ( $sex == 'F' && $age >= 60 )
in
the case where $sex
contains 'M'
$x
contains 0,
$y
contains 1 and $z
contains 2
if ( $num_of_faults != 0 && $total_downtime / $num_of_faults >= 3 ) { echo 'Average downtime is too high!'; }
if ( $total_downtime / $num_of_faults >= 3 && $num_of_faults != 0 ) { echo 'Average downtime is too high!'; }
if ( ! $nationality == 'Nerd' ) { … }
expr | ! expr |
---|---|
true | false |
false | true |
See:
if ( ! $nationality == 'Nerd' )
if ( $nationality != 'Nerd' )
if ( ! $age > 18 )
if ( ! $age >= 12 )
if ( ! $age < 100 )
if ( ! $age <= 65 )
if ( ! $nationality != 'Nerd' )
3 < 2 + 4
false && false || true
Operator | Precedence | Associativity |
---|---|---|
(int) , (float) , (string) , (bool) , etc. | high | right |
! | right | |
*, /, % | left | |
+, -, . | left | |
<, <=, >, >=, <> | n/a | |
==, !=, ===, !== | n/a | |
&& | left | |
|| | left | |
= | right | |
and | left | |
or | low | left |
3 < 2 + 4
false && false || true
if ( $sex == 'M' && $age > 65 || $age < 18 )
if ( ( $sex == 'M' && $age > 65 ) || $age < 18 )
if ( $sex == 'M' && ( $age > 65 || $age < 18 ) )
if ( ! $nationality == 'Nerd' && $age > 18 )
year.html
contains this form:
<form action="year.php" method="get"> <input type="text" name="year" /> <input type="submit" /> </form>
year.php
(next slide), which outputs whether the year
entered by the user is a leap year or not (use just one
if
statement)
year.php
$year = (int) $_GET['year']; $message = "<p>{$year} is not a leap year</p>"; if { $message = "<p>{$year} is a leap year</p>"; } echo $message;