DevelopPHP
home Forum gear home

Libraries book

HTML Library CSS Library JavaScript Library PHP Library

Videosbook

PHP and MySQL JavaScript HTML and CSS Vector and 3D Flash Actionscript Android Dev Miscellaneous

Resourcesbook

Website Hosting
Incremental and Decremental Operators   Share / Like
Incrementing and Decrementing operators are very widely used in most programming languages. They allow a PHP programmer to increment and decrement values as needed. Many times they are used in a loop to keep track of the index key number in the loop's array. We discuss loops in detail in later sections.

The following table shows their usage and result logic:
Name Usage Result
Pre-increment ++$myVar Increments $myVar by one
Post-increment $myVar++ Returns $myVar, then increments $myVar by one
Pre-decrement --$myVar Decrements $myVar by one, then returns $myVar
Post-decrement $myVar-- Returns $myVar, then decrements $myVar by one

Here is a code example of incrementing a variable's value by one:
Learn HTML
<?php
$myVar 
3;
// Use Post-increment to increment the value by 1
$myVar++;
// Now display to browser or use its new value in script
echo $myVar;
?>

Develop PHP browser display window
4



Home   •   Terms of Use   •   Developer Forums   •   T-Shirts   •   RSS   •   Classroom Chalkboard   •   Donate   •   Top ↑
Popular In PHP / MySQL E-Commerce Store Production
Social Network Website Building
Image Upload / Photo Processing
CMS Software Programming
Mass Email Systems
Magic XML Data
Search Programming
Popular In JavaScript JSON Programming
Ajax Programming
Animating Elements
WYSIWYG Programming
Date/Time Programming
DOM Scripting
Object Reference
Popular In HTML Canvas Element
New Form Elements
Audio Element
Video Element
Drag and Drop
Event Handling
Element Grouping
Popular In CSS Custom Font Embedding
Dynamic Fit Backgrounds
Theatre Mode
Box Overlays
CSS Level 1 Properties
CSS Level 2 Properties
CSS Level 3 Properties
©2013 DevelopPHP   |   Navigate to related domains HTML5