HTML and CSS Reference
In-Depth Information
One of the unique operators in PHP is the use of the dot ( . ) for concatenation. A compound
operator joins two operators into one for easier coding, and the .= compound operator takes
the let value and joins it with the right value. Another way of looking at it is that it assigns its
current value and the value assigned to it to make a third value, which becomes the variable's
new value.
h e arithmetic operators are fairly standard compared to other programming languages. h e
main ones include
+ (addition)
- (subtraction and negation)
/ (division)
* (multiplication)
% (modulo)
About the only one that anyone has problems with is modulo ( % ). It refers to any remainders
of whole numbers at er division. However, they can be handy. For example, the following little
program ( modulo.php in this chapter's folder at ),
demonstrates how it can be used with a Boolean:
for ( $count = 1 ; $count <= 12 ; $count ++) {
$valid = $count % 2 ;
if ( $valid )
echo $count , “ is odd<br>” ;
echo $count , “ is even<br>” ;
h e program iterates through a series of numbers divided by 2. Even numbers divided by 2
return 0 and odd numbers return 1 — the values Booleans recognize as false and true ,
respectively. h e if() statement is looking for a true or false and will accept ones and
zeros as Booleans. When sending out alternating backgrounds in table data coming from a
database, the modulo operator is used to switch colors back and forth using the trick of
dividing record numbers by 2 and using the remainder (modulo) as a Boolean.
At er all the work done with forms and dif erent types of input in HTML5, you'll i nd that
with a little PHP you can make e-mail forms with which users can send queries. h e i rst form
Search WWH ::

Custom Search