PHP Decrement Operator

by Hiroshi on June 21, 2008

in Decrement, PHP Basics

Some of the most frequently used code in PHP or any programming language is the code that will increment or decrement the value of a variable. This code or expression is used in programs as simple as a page counter or as complicated as credit card processing.

decrement() decrements value of the item by value. Consider the following example.

<?php
$num = 8;
echo "<br /> " . $num--;
echo "<br /> " . --$num;
// Output:
// 8
// 6
?>

Pre-decrement –$a
Decrements $a by one, then returns $a.

Post-decrement $a–
Returns $a, then decrements $a by one.

Related Posts

  • PHP Increment Operator Some of the most frequently used code in PHP or any programming language is the code […]
  • Simple PHP Script – Lets Start PHP – Echo Hello PHP If you want to learn PHP you have come to the right place. I will not only teach you how […]
  • PHP While Loop The while keyword takes a condition in parentheses, and the code block that follows is […]
  • PHP Do While Loop A "do while" loop is a slightly modified version of the while loop. A do-while loop […]
  • PHP Switch Statement Examples With the use of the switch statement you can check for many conditions at once, and the […]
  • PHP For Loop For loop consists of three phases. i.e. Define Condition Increment or […]
  • Action At Link Using PHP Use this example to show some hidden message at page using PHP. You can use two pages […]
  • PHP Functions A function is just a name we give to a block of code that can be executed whenever we […]
  • PHP ForEach Loop PHP provides an easy way to use every element of an array with the For each statement. […]
  • PHP Logical Operators Logical operators are true or false. NOT if(!1) Value is not one AND 4 && 4 […]

Previous post:

Next post: