Operator ini merupakan cabang matematika yang bersangkutan dengan penambahan, pengurangan, perkalian, pembagian, dan ekstraksi akar nomor-nomor tertentu yang dikenal sebagai bilangan real. Langsung saja berikut jenis-jenis operator aritmatika dan contohnya :
- Penjumlahan - ($x + $y)
- Pengurangan - ($x - $y)
- Perkalian - ($x * $y)
- Pembagian - ($x / $y)
- Modulus - ($x % $y) Dari contoh kode php dibawah ini menjelaskan bahwa pengertian modulus adalah sisa hasil bagi dari variabel $x terhadap $y.
- Eksponen - ($x ** $y) Eksponen adalah bentuk perkalian dengan bilangan yang sama yang di ulang-ulang atau singkatnya adalah perkalian yang diulang-ulang. Di tinjau dari bentuknya, bentuk xy, x disebut basis atau bilangan pokok dan y disebut eksponen atau pangkat. Berikut contohnya di kode PHP :
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$x = 10; | |
$y = 6; | |
echo $x + $y; // 10 + 6 = 16 adalah hasilnya | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$x = 10; | |
$y = 6; | |
echo $x - $y; // 10 - 6 = 4 adalah hasilnya | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$x = 10; | |
$y = 6; | |
echo $x * $y; // 10 * 6 = 60 adalah hasilnya | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$x = 10; | |
$y = 3; | |
echo $x / $y; # 10/3 = 3.3333333333333 adalah hasilnya | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$x = 100; | |
$y = 8; | |
echo $x % $y; // Hasilnya 4 | |
/* Sisa hasil bagi 100 oleh 8 adalah 4 | |
Logikanya 8 * 12 = 96, sisa 4 dari 100 dan tidak bisa di bagi 8 lagi */ | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$x = 8; | |
$y = 4; | |
echo $x ** $y; | |
// Hasilnya adalah 4096 | |
// Hasil dari 8 pangkat 4 atau 8 * 8 * 8 * 8 | |
?> |