Operator
Dalam PHP, operator dibagi menjadi 4 yaitu Arithmatic Operator, Assignment Operator, Comparison Operator dan Logical Operator.
- Arithmatic Operator
Operator | Deskripsi | Contoh | Hasil |
+ | Penjumlahan | x=6, x+10 | 16 |
- | Pengurangan | x=10, 13-x | 3 |
* | Pengalian | x=10, 2*x | 20 |
/ | Pembagian | 5/2 | 2.5 |
% | Modulus(Sisa Pembagian) | 5%2 | 1 |
++ | Increment | x=7, x++ | 8 |
-- | Decrement | x=7, x-- | 6 |
- Assignment Operator
Operator | Contoh | Sama Dengan |
= | 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 Operator
Operator | Deskripsi | TRUE | FALSE |
== | sama dengan | 2 == 2 | 2 == 3 |
!= | tidak sama dengan | 2 != 1 | 2 != 2 |
<> | tidak sama dengan | 2 <> 1 | 2 <> 2 |
> | lebih besar | 2 > 1 | 1 > 2 |
< | lebih kecil | 1 < 2 | 1 < 2 |
>= | lebih besar dan sama dengan | 2 >= 1 | 1 >= 2 |
<= | lebih kecil dan sama dengan | 1 <= 2 | 2 <= 1 |
- Operator Logical
Operator | Deskripsi | TRUE | FALSE |
&& | and | x = 8 | x = 8 |
y = 5 | y = 5 | ||
(x > 5 && y < 8) | (x > 10 && y < 3) | ||
|| | or | x = 8 | x = 8 |
y = 5 | y = 5 | ||
(x == 8 || y == 5) | (x == 5 || y == 8) | ||
! | not | x = 8 | x = 8 |
y = 5 | y = 5 | ||
!(x==y) | !(x==8) |
Posting Komentar