PHP Tutorial

PHP Operators and their usage with example code


PHP Operators

PHP operators are used to working on PHP variables & values and helps to get desire output.

PHP Operators are mainly a specific type of symbol that instructs the PHP to perform a particular operation.
e.g The add (+) symbol is an operator that informs PHP to add two or more variables or values, while the minus (-) symbol is an operator that informs PHP to subtract two or more values.

PHP has put the operators in the following categories:

  1. Arithmetic operators (+, -, *, /, **, %)
  2. String operators (.,.=)
  3. Assignment operators (=, +=, -=, *=, /=, %=)
  4. Logical operators or relational operators (and, or, xor, &&, ||, !)
  5. Comparison operators (==, ===, !=, <>, !==, >, <, >=, <=, <=>)
  6. Conditional assignment operators (?:, ??)
  7. Spaceship Operators (Introduced in PHP 7) (<=>)
  8. Array operators (+, ==, ===, !=, <>, !==)
  9. Increment/Decrement operators (++$variable, $variable++, –$variable, $variable–)

(1) Arithmetic operators (+, -, *, /, **, %)

To understand the use of arithmetic operators try the below example. Copy and paste the below-given PHP code in your PHP¬†file and put it in your PHP Server’s document root and open it on the browser.

The output of the above code:

output of arithmetic operators example code
The output of all the above codes will be like this.


About the author

Dinesh Sharma

I have worked on many CMS & Frameworks of PHP & I love to share my knowledge of what I am learning every day.

Add Comment

Click here to post a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.