PHP: Introduction Operator

Table of arithmetic operators


Sample Script aritmatika.php


$ value1 = 32; 
$ value2 = 8; 
$ number = $ value1 + $ value2; 
$ less = $ nilai1- $ value2; 
$ time = $ value1 * $ value2; 
$ to = $ value1 / $ value2; 
$ remainder = $ value1% $ value2; 
print "Reviews Arithmetic operation Example"; 
print "The value $ value1 = $ value1 and $ value2 = $ nilai2
"; 

print " $ value1 + $ value2 = $ amount most"; 
print " $ value1 - $ value2 = $ less than most"; 
print " $ value1 * $ value2 = $ times the most"; 
print " $ value1 / $ value2 = $ for most"; 
print " $ value1% $ value2 = $ leftovers most"; 
?>

The result:


Know the assigment operator

The following table of symbols and Functions of the assignment operator used

Example Scripts assignment.php

$data1=10;
$data1+=2;

print "Nilai $data1 adalah $data1

";
$data2=10;
$data2-=5;

print "Nilai $data2 adalah $data2

";
$data3=10;
$data3*=4;

print "Nilai $data3 adalah $data3

";
$data4=20;
$data4/=5;

print "Nilai $data4 adalah $data4

";
$data5=12;
$data5%=7;

print "Nilai $data5 adalah $data5";
?>


The result:



Know Comparison Operators

Table of comparison operators such as below

Example Scripts perbandingan.php

$a=12;
$b=13;

print "Variabel $a = $a dan $b = $b

";

print("Nilai $a == $b adalah %s
",$a==$b);
print("Nilai $a <> $b adalah %d
",$a<>$b);
print("Nilai $a > $b adalah %d
",$a>$b);
print("Nilai $a < $b adalah %d
",$a<$b);
print("Nilai $a <= $b adalah %d
",$a<=$b);
print("Nilai $a >= $b adalah %d

",$a>=$b);

print"Keterangan:
";
print "Nilai 1 berarti Benar/True
";
print "Nilai 0 berarti Salah/False";

?>


There are other operators are included in the category of comparison operators are ternary operator " ?". The use of the ternary operator is identical to the user if .. else . Pnggunaan example of the ternary operator is as follows:

Example Scripts ternary.php
























The result:



Know the String Operator

There are two types of operators used string operators . (Dot) operator . = (Colon equals) operator concatenate the arguments sent word to say that the right in an argument. While the operator . =Concatenate the arguments with a right hand to the left. The second function is similar operator to concatenate the words before and after. But the use of the operator. = More practical and operational results can be saved to the same variable. For more details, you can try the following script program. script String.php



$a="Selamat ";
$b=$a."Datang";
print "$b
";
$a="Selamat"; $b.="";print "$b
";
?>



The result:








If you have any questions please comment. 

Spread the love

Fajar (Ucup)

The owner and author of FajarYusuf.com and also someone who likes to share interesting information with others.

Leave a Reply

Your email address will not be published. Required fields are marked *