What are PHP Operators

What are PHP operators? As we know operators are symbols that are used to make mathematical predictions like addition, subtraction, multiplication, and division. PHP helps many operators to work not only with pure mathematical operations but also to implement some logical operations like AND, OR, NOT, comparison operations like greater than >, less than <, and many more. Operators are nothing that holds one or more value and yields another value.

Top 4 Types of PHP Operators

  1. Assignment Operator
  2. Arithmetic Operator
  3. String Operator
  4. INC/DEC Operator

Assignment PHP Operators

Assignment operators are used with numeric states to specify a value to a variable. In PHP, = is the primary assignment operator which implies that the left value goes set to the value of the assignment expression on the right. Following is the list of Assignment operators used in PHP

Simple Assignment Operator( = ): This operator Allows values from the right values to the left value.

Add AND Operator( += ): This operator computes the right value to the left value and allows the output to the left value.

Subtract AND Operator( -= ): This operator subtracts the right value from the left value and allows the result to the left value.

Multiply AND Operator( *= ): This operator calculates the right value with the left value and allows the result to the left value.

Divide AND Operator( /= ): This operator divides the left value with the right value and assigns the result to the left value.

Modulus AND Operator( %= ): This operator uses modulus using two values and assigns the result to the left value.

Arithmetic PHP Operators

Every Programming language has Arithmetic operators, PHP also supports Arithmetic operators which are used to complete simple arithmetical operations, such as addition, subtraction, division, multiplication, etc.

Addition Operator( + ): This operator is used to add two values. Suppose A and B are two values, this plus operators will add up these two values A + B.

$a + $b

Subtraction Operator( – ): This operator is used to subtract two values. Assume A and B are two values, then this minus operator will subtract the value of the second value from the first values A-B.

$a - $b

Multiplication Operator( * ): This operator is used to multiply two values. Assume A and B are two values then this multiplication operator will multiply A with B.

$a * $b

Division Operator( / ): This operator is used to numerator by the denominator. Assume A and B are two values, this division operator divides the numerator by the denominator.

$a / $b

Modulus Operator( % ): This operator is used to give the remainder of the division. Assume A and B are two values then this modulus operator first divides the numerator by denominator and gives the remainder.

String PHP Operators

String Operators are implemented over strings.

i) Concatenation( . ): This operator Concatenates Two strings.

$message1.$message2

Concatenation and assignment( .= ): This operator Appends two strings.

$message1.$message2

Increment/Decrement PHP Operators

These are called the unary operators as it operates on single operands. These operators are used to increment or decrement values.

i) Pre-Increment( ++ ): This operator initially increments $a by one, then return $a.

++$a

Pre-Decrement( — ): This operator initially decrements $a by one, then return $a.

--$a

Post-Increment( ++ ): This operator First returns $a, then increments it by one.

$a++

Pre-Decrement( — ): This operator first returns $a, then decrement it by one.

$a—

Conclusion

Operators are used to performing an important role in PHP when it comes to mathematical calculations. It also carries many operators like logical operators, string operators, etc.