CopyPastehas never been so tasty!

Pre and Post increment operators in PHP

by anonymous

  • 0
  • 0
  • 0
83 views


orignal source:http://codingvilla.com/pre-post-increment-operators-php-single-article-569.aspx

Pre - Post increment operators in PHP:

 

Pre and Post increment operators are unary operators that are used to add or subtract one from their operand. PHP also supports pre and post increment operators. This is also known as increment operator. These operators have no effect on Boolean variable.

 

Pre-Increment operator in PHP:

 

This operator increments an operand by one then return that operand using pre–increment in PHP. This operator first perform increment then return the result.

 

Syntax:

 

++$a

 

 

Code:

 

<?php

$answer = 5;

$pre=++$answer;

echo "Orignal value is 5 and preincremented value is: $pre<BR>";

?>

 

Post-Increment operator in PHP:

 

This operator returns operand and then increment 1 in that operand using post–increment in PHP. This operator return the result and then increment by one in operand.

 

 

Syntax:

 

 

$a++

 

 

Code:

 

 

<?php

$answer = 5;

$post=$answer++;

echo "Orignal value is 5 and postincremented value is: $post<BR>";

echo"after return operand increment then result is : $answer";

?>

 

 

Above is a simple code to check pre and post increment operators in PHP.

 

This simple article tells that how we do pre and post increment in PHP.

Add A Comment: