Skip to main content
  1. Study/
  2. Computer Programming/
  3. Web/
  4. Practicum Module I/

Web Programming I #04: Operator

·3 mins· loading
Azriel Fidzlie, S.Kom
Author
Azriel Fidzlie, S.Kom
Always Learning New Things
Table of Contents
Web Programming I Module - This article is part of a series.
Part 4: This Article

Understanding Operators
#

A programming language is also required to be able to process operand values (variables or constants being operated on) using operators, such as adding, dividing, and so on.

An operator is a symbol that functions to perform a specific action / operation on an operand value, which generally produces a new value from the result of the operation. While an operand is a value involved in the operation by the operator.

Types of Operators
#

  1. Arithmetic Operators These operators are used to perform mathematical calculations, as follows:
OperatorNameExampleResult
+Addition1+45
-Subtraction1-4-3
/Division1/40.25
*Multiplication1*44
%Modulus5%21
++IncrementX=5; X++X=6
-DecrementX=5; X-X=4

Script example:

Operatoraritmatika.php

<?php
$bil1=200;
$bil2=40;
$hasil = $bil1+$bil2;
echo "$bil1 + $bil2 = $hasil<br>";
$hasil = $bil1-$bil2;
echo "$bil1 - $bil2 = $hasil<br>";
$hasil = $bil1*$bil2;
echo "$bil1 * $bil2 = $hasil<br>";
$hasil = $bil1/$bil2;
echo "$bil1 / $bil2 = $hasil<br>";
?>

Result:

operator
  1. Comparison Operators Comparison operators are used to produce 2 values whose final result is a Boolean value of true and false. These operators are very useful in programming because they can determine the direction of programming. Comparison operators in PHP are:
OperatorNameExampleResult
==Equal to6 == 6False
!=Not equal to3!=3False
>Greater than1>5False
>=Greater than or equal to3>=4False
<Less than2<4True
<=Less than or equal to5<=4False

Opertorperbandingan.php

<?php
$bil1 = 200;
$bil2 = 40;
$teks1 = "PHP";
$teks2 = "php";

$hasil = $bil1 == $bil2;
echo "$bil1 == $bil2 = $hasil<br>";

$hasil = $bil1 != $bil2;
echo "$bil1 != $bil2 = $hasil<br>";

$hasil = $bil1 >= $bil2;
echo "$bil1 >= $bil2 = $hasil<br>";

$hasil = $teks1 == $teks2;
echo "$teks1 == $teks2 = $hasil<br>";

$hasil = $teks1 != $teks2;
echo "$teks1 != $teks2 = $hasil<br>";
?>

Result:

comparison

  1. Logical Operators Operators for composing logical expression statements. The result of this operation will get a value of one if true and zero if false.
OperatorFunction
AND or &&AND logical operation
OR or ||OR logical operation
XORExclusive OR logical operation
!Negation/NOT

Operatorlogika.php

<?php
$bil1 = 100;
$bil2 = 20;
$teks1 = "PHP";
$teks2 = "php";

$hasil = ($bil1 <> $bil2) or ($teks1 == $teks2);
echo "$bil1 <> $bil2 or $teks1==$teks2 adalah $hasil<br>";

$hasil = !($teks1 == $teks2);
echo "!($teks1==$teks2) adalah $hasil";
?>

Result:

logic
  1. String Operators In PHP there are also string operators, which are used for text concatenation operations. The symbol used is a dot (.) character.

Operatorstring.php

<?php

$teks1 = "Aku Sedang belajar";
$teks2 = "Pemrograman Web";
$teks3 = "Menggunakan bahasa script PHP";
$hasil = $teks1 . $teks2 . $teks3;

echo "$hasil ";
?>

Result:

string
Web Programming I Module - This article is part of a series.
Part 4: This Article

Related