Cover Image for PHP Operators
180 views

PHP Operators

In PHP, operators are symbols or special keywords that perform specific operations on one or more operands (variables, values, or expressions). PHP supports a wide range of operators, categorized into different types based on their functionality. Below are the main types of operators in PHP:

  1. Arithmetic Operators:
  • + Addition
  • - Subtraction
  • * Multiplication
  • / Division
  • % Modulo (returns the remainder of a division)
  1. Assignment Operators:
  • = Assigns the value on the right to the variable on the left
  • += Adds the value on the right to the variable on the left and assigns the result
  • -= Subtracts the value on the right from the variable on the left and assigns the result
  • *= Multiplies the variable on the left by the value on the right and assigns the result
  • /= Divides the variable on the left by the value on the right and assigns the result
  • %= Computes the modulo of the variable on the left by the value on the right and assigns the result
  1. Comparison Operators:
  • == Equality
  • != or <> Inequality
  • === Identity (equal value and equal type)
  • !== Non-identity (not equal value or not equal type)
  • > Greater than
  • < Less than
  • >= Greater than or equal to
  • <= Less than or equal to
  1. Logical Operators:
  • && or and Logical AND
  • || or or Logical OR
  • ! or not Logical NOT
  1. Increment/Decrement Operators:
  • ++ Increment by 1
  • -- Decrement by 1
  1. String Operators:
  • . Concatenation (joins two strings together)
  1. Array Operators:
  • + Union (combines arrays, elements from both arrays, duplicates removed)
  • == Equality (checks if both arrays have the same key/value pairs)
  • === Identity (checks if both arrays are identical)
  1. Ternary Operator:
  • expr1 ? expr2 : expr3 If expr1 is true, evaluates to expr2; otherwise, evaluates to expr3.
  1. Null Coalescing Operator (introduced in PHP 7):
  • ?? Returns the value of the left operand if it is not null; otherwise, returns the right operand.

These are the main operators in PHP. Understanding how to use them effectively is essential for writing efficient and concise PHP code.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS