![]() Back to www.deitel.com |
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
3
|
|
4 <!-- Fig. 26.4: operators.php -->
|
|
5 <!-- Demonstration of operators -->
|
|
6
|
|
7 <html xmlns = "http://www.w3.org/1999/xhtml">
|
|
8 <head>
|
|
9 <title>Using arithmetic operators</title>
|
|
10 </head>
|
|
11
|
|
12 <body>
|
|
13 <?php
|
|
14 $a = 5;
|
|
15 print( "The value of variable a is $a <br />" );
|
|
16
|
|
17 // define constant VALUE
|
|
18 define( "VALUE", 5 );
|
|
19
|
|
20 // add constant VALUE to variable $a
|
|
21 $a = $a + VALUE;
|
|
22 print( "Variable a after adding constant VALUE
|
|
23 is $a <br />" );
|
|
24
|
|
25 // multiply variable $a by 2
|
|
26 $a *= 2;
|
|
27 print( "Multiplying variable a by 2 yields $a <br />" );
|
|
28
|
|
29 // test if variable $a is less than 50
|
|
30 if ( $a < 50 )
|
|
31 print( "Variable a is less than 50 <br />" );
|
|
32
|
|
33 // add 40 to variable $a
|
|
34 $a += 40;
|
|
35 print( "Variable a after adding 40 is $a <br />" );
|
|
36
|
|
37 // test if variable $a is 50 or less
|
|
38 if ( $a < 51 )
|
|
39 print( "Variable a is still 50 or less<br />" );
|
|
40
|
|
41 // test if variable $a is between 50 and 100, inclusive
|
|
42 elseif ( $a < 101 )
|
|
43 print( "Variable a is now between 50 and 100,
|
|
44 inclusive<br />" );
|
|
45 else
|
|
46 print( "Variable a is now greater than 100
|
|
47 <br />" );
|
|
48
|
|
49 // print an uninitialized variable
|
|
50 print( "Using a variable before initializing:
|
|
51 $nothing <br />" );
|
|
52
|
|
53 // add constant VALUE to an uninitialized variable
|
|
54 $test = $num + VALUE;
|
|
55 print( "An uninitialized variable plus constant
|
|
56 VALUE yields $test <br />" );
|
|
57
|
|
58 // add a string to an integer
|
|
59 $str = "3 dollars";
|
|
60 $a += $str;
|
|
61 print( "Adding a string to variable a yields $a
|
|
62 <br />" );
|
|
63 ?>
|
|
64 </body>
|
|
65 </html>
|
|
|