Home arrow PHP arrow Page 4 - PHP Operators

Incremental Operators - PHP

What can you do without operators? Not much, if you're trying to do without them in a programming language, and PHP is no exception. On Monday, we barely had time to show you a long list of the operators in PHP. Today, we're going to show you what they do.

TABLE OF CONTENTS:
  1. PHP Operators
  2. Assignment Operators
  3. Arithmetic Operators
  4. Incremental Operators
  5. Better by Comparison
  6. Logical Operators
By: James Payne
Rating: starstarstarstarstar / 20
October 31, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Sometimes you want to increase or decrease the value of a variable by one. This is especially useful when using Loops, which we will cover in another tutorial. Here is an example of how you would work with them:


<html>

<body>


<?php


$value=9;


echo $value;

echo ++$value;


?>


</body>

</html>

The above code results in this print-out:

  9

  10

When the ++ appears before the variable it adds a one to it. If a –- appears before a variable it subtracts one from it.

Let's make it a little trickier. Consider the following code:


<html>

<body>


<?php


$value=9;


echo $value;

echo $value++;


?>


</body>

</html>

This code would result in:

  9

  9

That is because when we place the ++ after the variable name, it increments the value after the line of code is executed.


<html>

<body>


<?php


$value=9;


echo $value;

echo $value++; // increments the value by one after the line

echo $value; // prints the new value, which is now ten


?>


</body>

</html>

This code prints:

  9

  9

  10



 
 
>>> More PHP Articles          >>> More By James Payne
 

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 3 - Follow our Sitemap

Dev Shed Tutorial Topics: