Specifications
The following code:
$a = 1; $b = 2.5; $c = 1.9;
echo larger($a, $b).”<br>”;
echo larger($c, $a).”<br>”;
echo larger($d, $a).”<br>”;
will produce this output:
2.5
1.9
-1.7E+308
Functions that perform some task, but do not need to return a value, often return true or false
to indicate if they succeeded or failed. The values true and false can be represented with 1
and 0, respectively.
Code Blocks
We declare that a group of statements are a block by placing them within curly braces. This
does not affect most of the operation of your code, but has specific implications including the
way control structures such as loops and conditionals execute.
The following two examples work very differently.
Example Without Code Block
for($i = 0; $i < 3; $i++ )
echo “Line 1<br>”;
echo “Line 2<br>”;
Example with Code Block
for($i = 0; $i < 3; $i++ )
{
echo “Line 1<br>”;
echo “Line 2<br>”;
}
In both examples, the for loop is iterated through three times. In the first example, only the
single line directly below this is executed by the for loop. The output from this example is as
follows:
Line 1
Line 1
Line 1
Line 2
The second example uses a code block to group two lines together. This means that both lines
are executed three times by the for loop. The output from this example is as follows:
Using PHP
P
ART I
142
07 7842 CH05 3/6/01 3:35 PM Page 142