Type Casting
Type casting in
PHP works much as it does in C: the name of the desired type is written in
parentheses before the variable which is to be cast.
The casts allowed
are:
(int), (integer)
- cast to integer
(bool), (boolean)
– cast to boolean
(float),
(double), (real) - cast to float
(string) - cast
to string
(array) - cast to
array
(object) - cast
to object
(unset) - cast to
NULL (PHP 5)
Example:
<?php
echo (int) (
(0.1+0.7) * 10 ); // echoes 7!
?>
Operators
PHP supports the
following types of operators:
- Arithmetic operators
- Comparison operators
- Logical (or relational) operators
- Assignment operators
- Condition (or tertiary) operators