October 2002
Intermediate to advanced
368 pages
7h 12m
English
One of the most common PHP language constructs that you will encounter is the if/then statement. The if/then statement allows you to evaluate an expression and then, depending if it is true or not, take a course of action. For example:
$a = 1;
if($a) {
echo "True!";
}
Since $a = 1, then PHP interprets it in the context of the if statement to be a boolean type. Since 1 = true, the if statements prints out the message. Literally you can read it as “If True, then print out “True!”.
Another example, but this time with an “else” clause:
$a = 5;
$b = "10";
if($a > $b) {
echo "$a is greater than $b";
} else {
echo "$a is not greater than $b";
}
PHP doesn't care that $a is an integer and $b is a string. It recognizes that $b also ...
Read now
Unlock full access