Foundations
Conditionals
An if statement lets PHP choose between branches.
Conditionals
conditionals.php
<?php
$temperature = ;
$status = "";
if ($temperature >= 80) {
$status = "warm";
} else {
$status = "comfortable";
}
echo "temperature=" . $temperature . "\n";
echo "status=" . $status . "\n";
<?php
$temperature = ;
$status = "";
if ($temperature >= 80) {
$status = "warm";
} else {
$status = "comfortable";
}
echo "temperature=" . $temperature . "\n";
echo "status=" . $status . "\n";
<?php
$temperature = ;
$status = "";
if ($temperature >= 80) {
$status = "warm";
} else {
$status = "comfortable";
}
echo "temperature=" . $temperature . "\n";
echo "status=" . $status . "\n";
if statement
An `if` statement runs one block when its condition is true and can use `else` for the other case.