PHP Operators
Operators in PHP
What is an operator in PHP?
Operators in PHP languages is used to perform specific tasks. Tells the processor of PHP to do a specific tasks. (+) this symbols tells to add values.
Type of Operators
- Arithmetic Operators in PHP
- Assignment Operators in PHP
- Logical Operators in PHP
- Increment / Decrement Operator in PHP
- String Operators in PHP
- Comparison Operators in PHP
Arithmetic Operators in PHP
The term arithmetic is commonly known as the branch of mathematics which mostly used for the classical operations. In PHP arithmetic operation are of several types:
- Addition Operation in PHP
- Subtraction Operation in PHP
- Identity Operation in PHP
- Negation Operation in PHP
- Multiplication Operation in PHP
- Division Operation in PHP
- Modulus Operation in PHP
- Exponential Operation in PHP
Example of Athematic Operation of PHP
“;
“;
“;
“;
“;
“;
Output of Arithmetic Operators in PHP Code Example
Assignment Operator in PHP
An assignment operator in PHP is used to assign a value to a variable. For assigning a value in php ‘=’ sign is used variable name comes before equal and values that’s going to assign comes after the equal sign.
‘Variablename = Value’
Code example of Assignment Operator in PHP
Output of Assignment Operator in php
10
Hello WorldViewIT
Comparison Operator in PHP
Comparison Operators in php are of different types main purpose of these type of operators is to check the values or simply compare two values. So, the values are of two types (numeric, String).
Code Example of Comparison Operator in php
Output of Comparison Operators in PHP
Increment / Decrement Operators in PHP
In php increment operator is use for the increment (increase in value) in the values of variable.
So for decrement operator in php works vice versa of increment operator. It is use to decrease the value of variable.
Both increment and decrement operators have four types:
- Post Increment
- Post Decrement
- Pre Increment
- Pre Decrement
Post-increment operator in php is use to make increment after returning value of variable $w $w++.
Post-decrement operator in php is use to make decrease value after returning a value of variable $w $w–.
Pre-increment operator in php is use to make increment before returning a value of variable $w ++$w.
Pre-decrement operator in php is use to make decrement before returning a value of variable $w –$w.
Code Example of Increment / Decrement Operator in PHP
“;
“;
Output of Increment Decrement Operator in PHP
String Operator in PHP
String in php is a datatype click here to learn about strings in php. String operators in php is use to concatenate / combine to two string and also use to append two strings in php.
Code example of String Operator in PHP
Output of String Operators
Logical Operators in PHP
In php logical Operators are used to compare conditional statements as far as it is use in programs to make decisions.
Basic Logical Operators in php are followed below:
- And && (If two variables are True than True)
- OR || (If both of two variables anyone is true than True)
- Not ! (True if one is not true)
Code Example of Logical Operators in PHP
echo “Hello WorldViewIT
“;
}
{
echo “Hello WorldViewIT
“;
}
{
echo “Hello WorldViewIT OR Operator
“;
}
{
echo “Hello WorldViewIT OR Operator
“;
}
{
echo “Hello WorldViewIT Not Operator”;
}