PHP program using operators - In general programming language, the operator is used to manipulate or perform the calculation process on a variable value. Variables whose value is modified by the operator are called operands.
To understand more about the operator in PHP the following explanation.
To better understand about the operator in php, here I give examples of the use of the program using the php operator.
PHP program using operators
File Name: operator.php
Description: Program some arithmetic Operators in PHP.
Open notepad then input the following php code into notepad.
<?php
$salary = 1000000;
$tax = 0.1;
$taxyear = $salary - ($salary*$tax);
echo "Salary before tax = $. $salary <br>";
echo "The salary brought home = $. $taxyear";
?>
After that save with operator.php name (In the htdocs folder).
To see the results please open the browser and type in the address bar http://localhost/operator.php then the results will look like below.
File Name: operator2.php
Description: Logical programming and comparison operators in PHP.
Open notepad then type the following code into notepad.
<?php
$a = 5;
$b = 4;
echo "$a == $b : ". ($a == $b);
echo "<br>$a != $b : ". ($a != $b);
echo "<br>$a > $b : ". ($a > $b);
echo "<br>$a < $b : ". ($a < $b);
echo "<br>($a == $b) && ($a > $b) : ".(($a != $b) && ($a > $b));
echo "<br>($a == $b) || ($a > $b) : ".(($a != $b) || ($a > $b));
?>
Once the code is entered then save it with the name operator2.php (In the htdocs folder).
If you want to see the results please open the browser then type http://localhost/operator2.php on addres bar. Then the result will look like the following.
That's my article about php program using operators. Hopefully the article can add to our knowledge of the php programming language. Please understand the article and be practiced in order to better understand about php operator. Also read the article about How to Make Constant in PHP.
To understand more about the operator in PHP the following explanation.
Operator Type
|
Operator
|
Example
|
Information
|
Arithmetic
|
+
|
$a + $b
|
Addition
|
-
|
$a - $b
|
Subtraction
|
|
*
|
$a * $b
|
Multiplication
|
|
/
|
$a / $b
|
Division
|
|
%
|
$a % $b
|
Modulus
|
|
Assignment
|
=
|
$a = 4;
|
$ A is filled with 4
|
Bitwise
|
&
|
$a & $b
|
Bitwise AND
|
|
|
$a | $b
|
Bitwise OR
|
|
^
|
$a ^ $b
|
Bitwise XOR
|
|
~
|
~$b
|
Bitwise NOT
|
|
<<
|
$a << $b
|
Shift Left
|
|
>>
|
$a >> $b
|
Shift Right
|
|
Comparison
|
==
|
$a == $b
|
Equal
|
===
|
$a === $b
|
Identical
|
|
!=
|
$a === $b
|
Not equal
|
|
<>
|
$a <> $b
|
Not equal
|
|
!==
|
$a !== $b
|
Not identical
|
|
<
|
$a < $b
|
Greater than
|
|
>
|
$a > $b
|
Less than
|
|
<=
|
$a <= $b
|
Less than or equal to
|
|
>=
|
$a >= $b
|
Greater than or equal to
|
|
Logical
|
and
|
$a and $b
|
TRUE if $a dan $b TRUE
|
&&
|
$a && $b
|
TRUE if $a dan $b TRUE
|
|
or
|
$a or $b
|
TRUE if $a atau $b TRUE
|
|
||
|
$a || $b
|
TRUE if $a and/or $b TRUE
|
|
xor
|
$a xor $b
|
TRUE if $a or $b TRUE, But not both
|
|
!
|
!$a
|
TRUE if $a FALSE
|
|
String
|
.
|
$a . $b
|
Concatenation string $a dan $b
|
To better understand about the operator in php, here I give examples of the use of the program using the php operator.
PHP program using operators
File Name: operator.php
Description: Program some arithmetic Operators in PHP.
Open notepad then input the following php code into notepad.
<?php
$salary = 1000000;
$tax = 0.1;
$taxyear = $salary - ($salary*$tax);
echo "Salary before tax = $. $salary <br>";
echo "The salary brought home = $. $taxyear";
?>
After that save with operator.php name (In the htdocs folder).
To see the results please open the browser and type in the address bar http://localhost/operator.php then the results will look like below.
![]() |
Program View |
File Name: operator2.php
Description: Logical programming and comparison operators in PHP.
Open notepad then type the following code into notepad.
<?php
$a = 5;
$b = 4;
echo "$a == $b : ". ($a == $b);
echo "<br>$a != $b : ". ($a != $b);
echo "<br>$a > $b : ". ($a > $b);
echo "<br>$a < $b : ". ($a < $b);
echo "<br>($a == $b) && ($a > $b) : ".(($a != $b) && ($a > $b));
echo "<br>($a == $b) || ($a > $b) : ".(($a != $b) || ($a > $b));
?>
Once the code is entered then save it with the name operator2.php (In the htdocs folder).
If you want to see the results please open the browser then type http://localhost/operator2.php on addres bar. Then the result will look like the following.
![]() |
Program View |
That's my article about php program using operators. Hopefully the article can add to our knowledge of the php programming language. Please understand the article and be practiced in order to better understand about php operator. Also read the article about How to Make Constant in PHP.
Comments
Post a Comment