Operator is a symbol i.e used to perform operations on two operands. In others words, operators are used to perform action on variables or values. For example:
PHP divides the operators in the following groups:
Arithmetic operators
Assignment operators
Comparison operators
Increment/Decrement operators
Logical operators
String operators
Array operators
Conditional or Ternary Operators
Arithmetic operators
File Name :
The arithmetic operators are used to perform simple mathematical operations like addition, subtraction, multiplication and division etc.
Example :-
$x = 10;
$y = 6;
echo $x % $y;
?>
Output :-
4
Exponentiation
$x = 10;
$y = 3;
echo $x ** $y;
?>
Output :-
1000
Assignment operators :-
These operators are used to assign values to variable. The basic assignment operator in PHP is "=". It means that the left operand gets set to the value of the assignment expression on the right.
Comparison Operators
The PHP comparison operators are used to compare two values (number or string):
These operators are used to compare two elements and outputs the result in boolean form.
Increment/Decrement operators
These are called the unary operators as they work on single operands. These are used to increment or decrement values.
Logical operators :-
logical operators are used to combine conditional statements.
These are basically used to operate with conditional statements and expressions. Conditional statements are based on conditions. Also, a condition can either be met or cannot be met so the result of a conditional statement can either be true or false. Here are the logical operators along with their syntax and operations in PHP.
String operators :-
PHP has two operators that are specially designed for strings. This operator is used for the concatenation of 2 or more strings using the concatenation operator (‘.’). We can also use the concatenating assignment operator (‘.=’) to append the argument on the right side to the argument on the left side.
Conditional or Ternary Operators
conditional assignment operators are used to set a value depending on conditions. These operators are used to compare two values and take either of the results simultaneously, depending on whether the outcome is TRUE or FALSE. These are also used as a shorthand notation for if…else statement that we will read in the article on decision making.
$var = (condition)? value1 : value2;
Here, the condition will either evaluate as true or false. If the condition evaluates to True, then value1 will be assigned to the variable $var otherwise value2 will be assigned to it.