Page 91 - Open Soource Technologies 304.indd
P. 91
Open Source Technologies
Notes Additional Methods for Traversing Arrays
You can use other functions to iterate over arrays including current() and next(). You shouldn’t
use them because they are confusing and are legacy functions. In addition, some standard
functions allow all sorts of elegant ways of dealing with arrays such as array_walk(), which is
covered in a later unit.
6.1.3 Operators
PHP contains three types of operators: unary operators, binary operators, and one ternary
operator.
Binary operators are used on two operands:
2 + 3
14 * 3.1415
$i – 1
These examples are also simple examples of expressions. PHP can only perform binary operations
on two operands that have the same type. However, if the two operands have different types,
PHP automatically converts one of them to the other’s type, according to the following rules
(unless stated differently, such as in the concatenation operator).
Type of one of Type of the other Conversion Performed
the Operands Operand
Integer Floating point The integer operand is converted to a
floating point number.
Integer String The string is converted to a number. If the
converted string’s type is real, the integer
operand is converted to a real as well.
Real String The string is converted to a real.
Booleans, nulls, and resources behave like integers, and they convert in the following manner:
• Boolean: False = 0, True = 1
• Null = 0
• Resource = The resource’s # (id)
6.1.3.1 Binary Operators
Numeric Operators All the binary operators (except for the concatenation operator) work only
on numeric operands. If one or both of the operands are strings, Booleans, nulls, or resources,
they are automatically converted to their numeric equivalents before the calculation is performed.
Operator Name Value
+ Addition The sum of the two operands.
– Subtraction The difference between the two operands.
* Multiplication The product of the two operands.
Contd...
86 LOVELY PROFESSIONAL UNIVERSITY