PHP Operators
Tutorial ini menerangkan operator yang terdapat dalam PHP
Arithmetic Operators
| Operator | Keterangan | Contoh | Keputusan |
|---|---|---|---|
| + | Tambah |
x=2 x+2 |
4 |
| - | Tolak |
x=2 5-x |
3 |
| * | Darab |
x=4 x*5 |
20 |
| / | Bahagi |
15/5 5/2 |
3 2.5 |
| % | Baki |
5%2 10%8 10%2 |
1 2 0 |
| ++ | Penambahan |
x=5 x++ |
x=6 |
| -- | Pengurangan |
x=5 x-- |
x=4 |
Assignment Operators
| Operator | Contoh | Sama Seperti |
|---|---|---|
| = | 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 |
| %= | x%=y | x=x%y |
Comparison Operators
| Operator | Keterangan | Contoh |
|---|---|---|
| == | sama dengan | 5==8 returns false |
| != | tidak sama dengan | 5!=8 returns true |
| > | lebih besar dari | 5>8 returns false |
| < | kurang dari | 5<8 returns true |
| >= | lebih besar atau sama | 5>=8 returns false |
| <= | kurang atau sama | 5<=8 returns true |
Logical Operators
| Operator | Keterangan | Contoh |
|---|---|---|
| && | and |
x=6 y=3 (x < 10 && y > 1) returns true |
| || | or |
x=6 y=3 (x==5 || y==5) returns false |
| ! | not |
x=6 y=3 !(x==y) returns true |



Kemas kini: Aug 12, 2011