Home

PHP Operators



Sumber : Sourcecodester.com
Dalam setiap bahasa pemrograman, operator memainkan peran penting. Hal ini dapat digunakan dalam laporan perbandingan seperti IF pernyataan, loop pernyataan seperti loop WHILE, menempatkan nilai ke variabel dan banyak lagi.

Comparison Operators

OperatorDescriptionExample
>=is greater than or equal to4>=9 returns false
<=is less than or equal to5<=7 returns true
is less than2<7 returns true
is greater than3>9 returns false
<> is not equal2<>3 returns true
!=is not equal4!=8 returns true
==is equal to2==1 returns false
Example of comparison operators in IF statement:
  1. <?php
  2. If (4>=9){
  3. //the statement here will not be executed
  4. }
  5. ?>

Arithmetic Operators

OperatorDescriptionExampleResult
*Multiplicationx=2
x*3
6
/Division9/3
10/2
3
5
+Additionx=3
x+4
7
-Subtractionx=1
5-x
4
--Decrementx=4
x--
x=3
++Incrementx=7
x++
x=8
%Modulus (division remainder)5%2
10%8
10%2
1
2
0
Example of arithmetic operators in mathematics:
  1. <?php
  2. $x = 2;
  3. $y = $x + 3;
  4. echo $y;
  5. ?>

Logical Operators

OperatorDescriptionExample
&&andx=8
y=2
(x < 10 && y > 1) returns true
!notx=7
y=2
!(x==y) returns true
||orx=8
y=2
(x==8 || y==2) returns false
Example of logical operators is IF statement:
  1. <?php
  2. $x=8
  3. $y=2
  4. If ($x==8 || $y==2){
  5. //the statement here will be executed
  6. }
  7. ?>

Assignment Operators

OperatorExampleIs The Same As
+=a+=ba=a+b
*=a*=ba=a*b
=a=ba=b
.=a.=ba=a.b
-=a-=ba=a-b
%=a%=ba=a%b
/=a/=ba=a/b
Example of assignment operators in a variable x and y:
  1. <?php
  2. $x = 2;
  3. $y = $x + 3;
  4. ?>

Unknown

Tempat Tutorial coding dan contoh-contoh aplikasi baik itu php,mysql,android,java, dan html.

Tidak ada komentar:

Posting Komentar