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
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- 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...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: