Table of Contents
- Operator Precedence
- Arithmetic
- Increment and Decrement
- Assignment
- Bitwise
- Comparison
- Error Control
- Execution
- Logic
- String
- Array
- Type
An operator is something that takes one or more values (or expressions, in programming jargon) and yields another value (so that the construction itself becomes an expression).
Operators can be grouped according to the number of values they take. Unary operators take only one value, for example !
(the logical not operator) or ++
(the increment operator). Binary operators take two values, such as the familiar arithmetical operators +
(plus) and -
(minus), and the majority of PHP operators fall into this category. Finally, there is a single ternary operator, ? :
, which takes three values; this is usually referred to simply as "the ternary operator" (although it could perhaps more properly be called the conditional operator).
A full list of PHP operators follows in the section Operator Precedence. The section also explains operator precedence and associativity, which govern exactly how expressions containing several different operators are evaluated.
Improve This Page
+add a note
User Contributed Notes 4 notes
up
down
250
Anonymous ¶
19 years ago
AND is not the same like && for example: <?php $a && $b || $c; ?> the second 'cause || has got a higher priority than and, but less than && of course, using always [ && and || ] or [ AND and OR ] would be okay, but than you should at least respect the following: <?php $a = $b && $c; ?> maybe usefull for some tricky coding and helpfull to prevent bugs :D greetz, Warhogof course this should be clear, but i think it has to be mentioned espacially:
is not the same like
<?php $a AND $b || $c; ?>
the first thing is
(a and b) or c
a and (b or c)
<?php $a = $b AND $c; ?>
the first code will set $a to the result of the comparison $b with $c, both have to be true, while the second code line will set $a like $b and THAN - after that - compare the success of this with the value of $c
up
down
52
anisgazig at gmail dot com ¶
3 years ago
Operator are mainly divided by three groups. Operator are mainly divided by three groups that are totally seventeen types. 2.Assignment Operator 3.Array Operator 4.Bitwise Operator 5.Comparison Operator 6.Execution Operator 7.Error Control Operator 8.Incrementing/Decrementing Operator 9.Logical Operator 10.string Operator 11.Type Operator 12.Ternary or Conditional operator 13.Null Coalescing Operator 14.Clone new Operator 15.yield from Operator yield from = yield from 16.yield Operator 17.print OperatorOperator are used to perform operation.
1.Uniary Operators that takes one values
2.Binary Operators that takes two values
3.ternary operators that takes three values
1.Arithmetic Operator
+ = Addition
- = Subtraction
* = Multiplication
/ = Division
% = Modulo
** = Exponentiation
= "equal to
+ = Union
== = Equality
=== = Identity
!= = Inequality
<> = Inequality
!== = Non-identity
& = and
^ = xor
| = not
<< = shift left
>> = shift right
== = equal
=== = identical
!= = not equal
!== = not identical
<> = not equal
< = less than
<= less than or equal
> = greater than
>= = greater than or equal
<=> = spaceship operator
`` = backticks
@ = at sign
++$a = PreIncrement
$a++ = PostIncrement
--$a = PreDecrement
$a-- = Postdecrement
&& = And
|| = Or
! = Not
and = And
xor = Xor
or = Or
. = concatenation operator
.= concatenating assignment operator
instanceof = instanceof
?: = Ternary operator
??" = null coalescing
clone new = clone new
yield = yield
print = print
up
down
23
yasuo_ohgaki at hotmail dot com ¶
23 years ago
Note: If you write following code, you would need "()" to get expected value. <?phpOther Language books' operator precedence section usually include "(" and ")" - with exception of a Perl book that I have. (In PHP "{" and "}" should also be considered also). However, PHP Manual is not listed "(" and ")" in precedence list. It looks like "(" and ")" has higher precedence as it should be.
$bar = true;
$str = "TEST". ($bar ? 'true' : 'false') ."TEST";
?>
Without "(" and ")" you will get only "true" in $str.
(PHP4.0.4pl1/Apache DSO/Linux, PHP4.0.5RC1/Apache DSO/W2K Server)
It's due to precedence, probably.
up
down
5
figroc at gmail dot com ¶
15 years ago
The variable symbol '$' should be considered as the highest-precedence operator, so that the variable variables such as $$a[0] won't confuse the parser. [http://www.php.net/manual/en/language.variables.variable.php]
+add a note