Array Operators
| operators | Name | Result |
|---|
| $a + $b | Union | Union of $a and $b. | | $a == $b | Equality | TRUE if $a and $b have the same key/value pairs. | | $a === $b | Identity | TRUE if $a and $b have the same key/value pairs in the same
order and of the same types. | | $a != $b | Inequality | TRUE if $a is not equal to $b. | | $a <> $b | Inequality | TRUE if $a is not equal to $b. | | $a !== $b | Non-identity | TRUE if $a is not identical to $b. |
String Operators
There are two string operators. The first is the concatanation operator ('.'), which returns the concatenation of its right and left arguments.
The second is the concatenating assignment operator ('.='), which appends the argument on the right side to the argument on the left side.
Error Control Operators
PHP supports one error control operator: the at sign (@). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.
Eg :- @file ('non_existent_file');
Execution Operators
PHP supports one execution operator : backticks (``).
Incrementing/Decrementing Operators
PHP supports C-style pre- and post-increment and decrement operators.
| Operator | Name | Effect |
|---|
| ++$a | Pre-increment | Increments $a by one, then returns $a. | | $a++ | Post-increment | Returns $a, then increments $a by one. | | --$a | Pre-decrement | Decrements $a by one, then returns $a. | | $a-- | Post-decrement | Returns $a, then decrements $a by one. |
Examples
<?php
$var= 5 + 5; // 10
$var = 5 - 5; // 0
$var = 5 + 5 - (5 + 5); // 0
$var = 5 * 5; // 25
$var = 10 * 5 - 5; // 45
Modulus
for ($i = 1; $i <= 10; $i++) {
if(($i % 2) == 1) //odd
{echo $i."is odd number";}
else //even
{echo $i."is even number";}
}
?>
|