PHP Pre/Post Increment Decrement Operator example tutorial

How to use pre increment, pre decrement, post increment, post decrement operator in php program script.

Pre-Post increment decrement operator are used to increment and decrement variables in php program. So here is the complete step by step tutorial for PHP Pre/Post Increment Decrement Operator example tutorial.

android-project-download-code-button

Pre Increment operator ( ++$variable ) : Pre increment operator first increment the variable by plus one into current variable value then return the variable.

Post Increment operator ( $variable++ ) : Using Post increment operator first it will return variable value then it will increment the variable with plus one.

Pre Decrement operator ( — –$variable ) : Pre decrement variable first decrease variable value with minus one the it will return the variable.

Post Decrement operator ( $variable– –) : Post decrement operator firstly returns variable value then it will minus one the variable.

PHP Pre/Post Increment Decrement Operator example tutorial.

Code for Increment-Decrement-program.php file.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PHP Pre/Post-Increment Decrement Operator example tutorialt</title>
</head>

<body>

<?php

$one = 5;

// Pre increment operator first increase $one value with one then transfer it into $three.
echo $three = ++$one .'</br>' ;

//Post increment operator first transfer the $one variable value to $three then increase one.
echo $three = $one++ .'</br>';

// Pre decerement first decrease variable value with minus one then transfer to other variable.
echo $three = --$one .'</br>';

// Post decerement first transfer value to other variable then increase one.
echo $three = $one-- ;

?>

</body>
</html>

Screenshot :

PHP Pre/Post Increment Decrement Operator example tutorial

Click here to download PHP Pre/Post-Increment Decrement Operator example tutorial project file.

Leave a Reply

Your email address will not be published. Required fields are marked *