A simple solution can be provided by using the expression 4 + 5 = 9. In this case, the operands are 4 and 5, and the operator is +. The PHP language supports the following operators.

  • Operators in figures
  • Operators of Contrast
  • Operators that are logical (or relational).
  • Operators in Charge of Assignment
  • Operators that are conditional (or ternary) in nature
Types of PHP operatives.

Operators in Computation

The PHP language supports the following arithmetic operators:

Assume variable A has a value of 10 and variable B has a value of 20, then

OperatorDescriptionExample
+two operands are addedA + B equals 30.
Subtraction of the second operand from the first
A – B equals -10.
*Add the two operand pieces together.A * B will give 200
/Divide the numeration by the denominator.
A * B equals 200.
%After an integer division, the modulus operator and the remainder of
B % A equals 0
++The increment operator increases the value from an integer to an integer.A++ will result in a score of 11.
Operator Decrement, reduces an integer value.A— will provide 9

Comparative Operator

The PHP language supports the following comparison operators:

Assume variable A has a value of 10 and variable B has a value of 20, then

OperatorDescriptionExample
==Verify that the values of two operands are equal; if this is the case, the condition is true.(A == B) is not correct.
!=Checks if the values of two operands are equal; if the values are not equal, the condition is true.(A!= B) is correct.
>If the value of the left operand is larger than the value of the right operand, the condition is true.(A > B) is not correct.
<If the value of the left operand is smaller than the value of the right operand, the condition is satisfied.(A B) is correct.
>=If the value of the left operand is more than or equal to the value of the right operand, the condition is satisfied.(A >= B) is not correct.
<=If the value of the left operand is less than or equal to the value of the right operand, the condition is true.(A = B) is correct.

Logical Operators are a type of logic.

The PHP language supports the following logical operators:

Assume variable A has a value of 10 and variable B has a value of 20, then

OperatorDescriptionExample
andThis is known as the Logical AND operator. If both operands are true, the condition is true.(A and B) are correct.
orThis is known as the Logical OR Operator. If any of the two operands is not zero, the condition is satisfied.(A or B) is correct.
&&This is known as the Logical AND operator. If both operands are non-zero, the condition is satisfied.(A && B) is correct.
||Known as the Logical OR Operator. If any of the two operands is non-zero, the condition is satisfied.(A || B) is correct.
!This is known as the Logical NOT Operator. To reverse the logical state of its operand, use. If a condition is true, then the Logical NOT operator returns false.! (A && B) is incorrect.

Operators in Charge of Assignment

The PHP language supports the following assignment providers.

OperatorDescriptionExample
=The assignment operator is a simple operator that assigns values from the right side operands to the left side operands.C = A + B will assign the value of A Plus B to C.
+=The AND assignment operator adds the right operand to the left operand and assigns the result to the left operand.C += A is the same as C = C + A.
-=The subtract AND assignment operator subtracts the right operand from the left operand and assigns the result to the left operand.C -= A is the same as C = C – A.
*=The multiplication AND assignment operator multiplies the right operand by the left operand and assigns the result to the left operand.C *= A is the same as C = C * A.
/=The divide AND assignment operator divides the left operand by the right operand and assigns the result to the left operand.C = C / A is the same as C = C / A.
%=It accepts modulus with two operands and assigns the result to the left operand using the modulus AND assignment operator.C%= A is the same as C = C% A.

Operator with a type of condition

There is also a conditional operator. This examines an expression to determine if it is true or false and then executes one of the two supplied statements based on the outcome of the evaluation. This is the syntax for the conditional operator

OperatorDescriptionExample
?Expression with such a ConditionIf the condition has been met? Otherwise, value Y.

Classification of Operators

All of the operators covered above may be divided into the following categories:

  • Unary prefix operators are those that precede one operation.
  • Binary operators are used to execute a variety of arithmetic and logical operations on two operands.
  • The conditional operator (a ternary operator) accepts three operands and evaluates either the second or third expression based on the first expression’s evaluation.
  • Operators used in assignments that give a variable a value

PHP Operators Take First Place

The order of words in an expression is determined by operator precedence. This has an impact on how an expression is assessed. Certain operators are more important than others; for example, the multiplication operator is more important than the addition operator.

Categorized in: