w3pop.com :: ÍøÂçѧԺ :: PHP :: PHP²Ù×÷·û
Operators are used to operate on values.
²Ù×÷·û£¨Operator£©ÊÇÓÃÀ´¶ÔÒ»¸öÖµ½øÐвÙ×÷µÄ¡£
This section lists the different operators used in PHP.
ÏÂÃæµÄÁбíÂÞÁÐÁËPHPÖв»Í¬µÄ²Ù×÷·û£¬ÒÔ¼°ËüÃDz»Í¬µÄÓ÷¨£º
Arithmetic Operators
ÔËËã·û£¨Arithmetic Operators£©
| Operator ·ûºÅ |
Description ÃèÊö |
Example °¸Àý |
Result ½á¹û |
|---|---|---|---|
| + | Addition ¼ÓºÅ |
x=2 x+2 |
4 |
| - | Subtraction ¼õºÅ |
x=2 5-x |
3 |
| * | Multiplication ³ËºÅ |
x=4 x*5 |
20 |
| / | Division ³ýºÅ |
15/5 5/2 |
3 2.5 |
| % | Modulus (division remainder) ÇóÄ££¨ÓàÊý£© |
5%2 10%8 10%2 |
1 2 0 |
| ++ | Increment ×Ô¼Ó |
x=5 x++ |
x=6 |
| -- | Decrement ×Ô¼õ |
x=5 x-- |
x=4 |
Assignment Operators
·ÖÅä·û£¨Assignment Operators£©
| Operator ·ûºÅ |
Example °¸Àý |
Is The Same As µÈͬÓÚ |
|---|---|---|
| = | x=y | x=y |
| += | x+=y | x=x+y |
| -= | x-=y | x=x-y |
| *= | x*=y | x=x*y |
| /= | x/=y | x=x/y |
| %= | x%=y | x=x%y |
Comparison Operators
±È½Ï·û£¨Comparison Operators£©
| Operator ·ûºÅ |
Description ¾ßÌåÃèÊö |
Example °¸Àý |
|---|---|---|
| == | is equal to µÈÓÚ |
5==8 ·µ»Ø false |
| != | is not equal ²»µÈÓÚ |
5!=8 ·µ»Ø true |
| > | is greater than ´óÓÚ |
5>8 ·µ»Ø false |
| < | is less than СÓÚ |
5<8 ·µ»Ø true |
| >= | is greater than or equal to ´óÓÚµÈÓÚ |
5>=8 ·µ»Ø false |
| <= | is less than or equal to СÓÚµÈÓÚ |
5<=8 ·µ»Ø true |
Logical Operators
Âß¼ÅжϷû£¨Logical Operators£©
| Operator ·ûºÅ |
Description ÃèÊö |
Example °¸Àý |
|---|---|---|
| && | and Óë |
x=6 y=3 (x < 10 && y > 1) ·µ»Ø true |
| || | or »ò |
x=6 y=3 (x==5 || y==5) ·µ»Ø false |
| ! | not ·Ç |
x=6 y=3 !(x==y)·µ»Øtrue |
ÆÀÂÛ (0)
All