Tag Archives: Objectives

PHP Increment/decrement Operator

Incrementing and Decrementing Operators

There are two types of incrementing and decrementing operators, post incrementing/decrementing operators and pre incrementing /decrementing operators. Post incrementing operators are placed after a variable name, and pre incrementing /decrementing operators are placed before the name.

Operator Usage Output
Post incrementing $a++; Returns the value of $a and then adds 1 to the value
Post decrementing $a–; (2 minus signs) Returns the value of $a and then subtract 1 from the value
Pre incrementing ++$a; Adds 1 to the value of $a and then returns the new value
Pre decrementing –$a; (2 minus signs) Subtract 1 from the value of $a and returns the new value

Consider the fallowing code for a better understanding of incrementing and decrementing operators. This code shows how the post incrementing operators works.

Post Incrementing Operator
$a = 8;
$b = $a++;
echo $b; //Returns the value 8.
echo $a; //Returns the value 9.
Post Decrementing Operator
$a = 10;
$b = $a--;
echo $b; // Returns the value 5.
echo $a; // Returns the value 4.
Pre Incrementing Operator
$a = 8;
$b = ++$a;
echo $b; // Returns the value 9.
echo $a; // Returns the value 9.
Pre Decrementing Operator
$a = 10;
$b = --$a;
echo $b; // Returns the value 9.
echo $a; // returns the value 9.

String Operator

When you start writing PHP code, you will realize the importance of string operators. PHP uses twokinds of string operators, concatenation (.) the dot sign and concatenating assignment (.=) the dot and equal to sign.The concatenation operator is used when you want to combine the left and right argument between which the operator is placed. The concatenating assignment operator is a combination of the concatenation operators and the assignment operator.

Concatenation Operator
   $a = "My name is ";
   $b .= "Rishi";
   echo $b;

The output of the code is: My name is Rishi.

Concatenating Assignment operator
  $a = "My name is";r/>  $a.= "Rishi";
  echo $a;

The output of the code is: My name is Rishi.

Logical Operators

The Logical operators are used in PHP to determine the status of condition . When you use if…else or while statements, logical operator execute code based on the status of a condition .In this section, we will discuss only two logical operators:

The and operate (&&) is used when a statement has two condition to be checked. If both the condition are true , the statement is true,.

The or operator ( || ) is also used when a statement has two condition is true, the statement is true.

  $a = 10;
  $b = 15;
  $c = $a + $b;
  if( ($a > 5) && $c < 20 ){
    echo "Value of c is less than 20";
  }else {
    echo "Value of c is more than 20"; 

The Output of the above code is: Value of c is more than 20

PHP Arithmetic Operator

Arithmetic operators

Arithmetic operators are used to perform elementary mathematical calculation and are used when value of variable declare in integer type.

Name Example Output
Addition $a+$b The sum of $a and $b
Subtraction $a-$b The difference between $a and $b
Multiplication $a*$b The product of $a and $b
Division $a/$b The quotient of $a and $b
Modules $a%$b The remainder after dividing $a and $b

Let us look at some examples for a better understanding of arithmetic operators:

$a = 3;
$b = 6;
$c = $a+$b ; // The value of $c is now 9.
$a = 11;
$b = 2;
$c = $a-$b; //The value of $c is now 9.
$a = 3;
$b = 3;
$c = $a*$b; //The value of $c is now 9.
$a = 18;
$b = 2;
$c = $a/$b ; //The value of $c is 9.
$a = 9;
$b = 3;
$c = $a%$b; //The value of $c is now 0.

Enterprise Resource Planning

“Optimize the company’s business processes by IWCn ERPs”


IWCn offers ERP modules implementation for companies that look for strengthening their competitive edge with smart technology and business process engineering.To address your business needs IWCn offers scalable and cost-effective solutions approach and relevant industry/domain experience.

Continue reading