Operator | Name | Example | Result |
---|---|---|---|
. | Concatenation | $txt1 = "Hello" $txt2 = $txt1 . " world!" | Now $txt2 contains "Hello world!" |
.= | Concatenation assignment | $txt1 = "Hello" $txt1 .= " world!" | Now $txt1 contains "Hello world!" |
The example below shows the results of using the string operators:
<?php
$a = "Hello";
$b = $a . " PHP!";
echo $b; // outputs Hello PHP!
$x="Hello";
$x .= " PHP!";
echo $x; // outputs Hello PHP!
?>
Logical Operators
There are following logical operators supported by PHP language
Assume variable A holds 10 and variable B holds 20 then −
Operator | Description | Example |
---|---|---|
and | Called Logical AND operator. If both the operands are true then the condition becomes true. | (A and B) is true. |
or | Called Logical OR Operator. If any of the two operands are non zero then condition becomes true. | (A or B) is true. |
&& | Called Logical AND operator. If both the operands are non zero then the condition becomes true. | (A && B) is true. |
|| | Called Logical OR Operator. If any of the two operands are non zero then condition becomes true. | (A || B) is true. |
! | Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. | !(A && B) is false. |
There is one more operator called a conditional operator. This first evaluates an expression for a true or false value and then execute one of the two given statements depending upon the result of the evaluation. The conditional operator has this syntax −
Operator | Description | Example |
---|---|---|
? : | Conditional Expression | If Condition is true ? Then value X : Otherwise value Y |
© 2024 Easy To Learning. All Rights Reserved | Design by Easy To Learning