CodesJava

Easy learning with example program codes

PHP Operators


PHP Operators are used to perform operations on operands. Operands can be a variable or a constant. The operators are divided into various groups on the basis of the basic operations they perform.

Arithmetic Operators: 

The operators which are used to perform the arithmetical operations, are grouped together as Arithmetic operators.

OperatorsSymbol
Addition+
Subtraction
Multiplication*
Division/
Modulus%
Exponentiation**

 

Assignment Operators: 

The operators which are used to assign values to a variable, are grouped together as Assignment operators.

OperatorsSymbol
Equals To=
Added Value+=
Subtracted Value-=
Multiplicated Value*=
Divided Value/=
Modulus Value%=

 

Comparison Operators: 

The operators which are used to compare two values, are grouped together as Comparison operators.

OperatorsSymbol
Equal==
Identical===
Not equal!=, <>
Not identical!==
Greater than>
Less than<
Greater than or equal to>=
Less than or equal to<=

 

Increment/ Decrement Operators: 

The operators which are used to increment or decrement the value of a variable, are grouped together as Increment and Decrement operators.

OperatorsSymbol
Pre-Increment++$x
Post-Increment$x++
Pre-Decrement–$x
Post-Decrement$x–

 

Logical Operators: 

The operators which are used to perform logical operations, are grouped together as Logical operators.

OperatorsSymbol
ANDAnd, &&
OROr, ||
XORxor
NOT!

 

String Operators: 

The operators which are used to perform operations on string, are grouped together as String operators.

OperatorsSymbol
Concatenation.
Concatenation assignment.=

 

Array Operators: 

The operators which are used to perform operations on array, are grouped together as Array operators.

OperatorsSymbol
Union+
Equality==
Identity===
Inequality!=, <>
Non-Identity!==

Example:

<!DOCTYPE html>
<html>
<body>
 
<?php
$txt1 = "Sum of 1234 and 4321 is:";
$txt2 = “Difference of 1234 and 4321 is:";
$txt3 = “Product of 1234 and 4321 is:";
$txt4 = “Quotient of 1234 and 4321 is:";
 
$x = 1234;
$y = 4321;
 
echo "<h3>" . $txt1 . "</h3>";
echo $x + $y;
 
echo "<h3>" . $txt2 . "</h3>";
echo $x - $y;
 
echo "<h3>" . $txt3 . "</h3>";
echo $x * $y;
 
echo "<h3>" . $txt4 . "</h3>";
echo $x / $y;
 
?>
 
</body>
</html>
Please follow and like us:
Posted in PHP   


Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki