Raza Bayani

PHP Tutorails 5: PHP Operators and Kinds’

PHP Tutorails 5: PHP Operators and Kinds’

After the discussing about the “First PHP Project“, “How to Print” and “Variables in PHP“, we are now going to learn about PHP Operators in this tutorial.

PHP Operators:

Actually operators perform operations on the data (values and variables) and return or give the outcome to us. For example in the below codes, (+) operator is performing the operation (adding two numbers).

Kinds of Operators:

Operators are divided into different groups in php. Below you can see the list of different groups of operators in PHP.

  1. Arithmetic operators
  2. Assignment operators
  3. Comparison operators
  4. Increment/Decrement operators
  5. Logical operators
  6. String operators
  7. Array operators

Arithmetic PHP Operators:

The PHP arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc.

Arithmetic operators are actually those mathematics operators which we learned in primary classes.

Operator Name Example Result
+ Addition $x + $y Sum of $x and $y
Subtraction $x – $y Difference of $x and $y
* Multiplication $x * $y Product of $x and $y
/ Division $x / $y Quotient of $x and $y
% Modulus $x % $y Remainder of $x divided by $y
** Exponentiation $x ** $y Result of raising $x to the $y’th power (Introduced in PHP 5.6)

Let’s work on example: create a new php file and save it in the directory we mentioned in second tutorial. Put the following codes inside and run the file through local server:

Assignment Operators:

The PHP assignment operators are used with numeric values to write a value to a variable. The basic assignment operator in PHP is “=”. Values on right side of the (=) are assigned to variables on the left. E.g.:

Operator Operation Discription
x = y x = y The left operand gets set to the value of the expression on the right
x += y x = x+y Addition
x -=y x= x-y Subtraction
x *=y x = x* y Multiplication
x /= y x = x/y Division
x %=y x = x%y Modulus

Other Operators will be discussed on the next tutorial. Stay tuned with codejow.com

Raza Bayani
Raza Bayani

Raza Bayani studies BCE (Bachelor in Computer Engineering) in Poly-technical University of Kabul. He is the CEO of CODEJOW group, a web designer, coder and recently a blogger. Raza thinks, he can help others and also boost-up his own programming skills being on codejow.com.

Related Posts
%d bloggers like this: