Home
Username:
Password:
PHP Tutorials

Absolute Basics / More complex Operators pt. 2

Subtitles of the Movie

There are also two other more concise operators that we use a lot within our code. The first of these is the increment, so let’s set our num variable to 10 and we can say num variable and then we use this increment operator, which is simply ++ with no space, we just write ++ and then we end our line with a semi colon. Now let’s see what that does. See what that's done to our variable. We’ll save that and check it in our browser. It gives us the value 11, so all the increment operator does is add one to whatever variable you’re applying it to. Same goes for the decrement operator except of course it takes away 1 from the variables value. So in this case, num will be reduced by one and the number 9 would be echoed to the browser. There are two different ways in which we can implement these increment and decrement operators and they’ll become clear as we combine, for instance our echo statement with the operator for instance, if we say echo num ++, what this does is it adds one to the variable nums value but it wont do it until after this statement is carried out. So let’s take a look at what that shows us. If we refresh, see what this script does. Shows us the value 10. This is because the increment is carried out after the statement is made. So if we add another echo command and check that out in the browser, We’ll see that the number 10 is written and then the number 11. Let’s make that a little clearer. We can use html tag, which I’m sure you’re familiar with 'br' to put a space in there. This can prevent some confusion, there, our numbers 10 and 11. So the first number is the result of this echo command and as we can see that increment hasn't been carried out yet and the second number is after that increment has been carried out. Now there is a way of applying the increment and making it happen before the statement is evaluated. If we put it before the variable, then this is known as a pre increment. Let’s save that and take a look in our browser. As we can see, both times the variable outputs the value 11. This is because we’ve used our special pre increment operator. The same of course goes for our decrement operator and as we can see, we refresh the browser, both times the variable outputs 9. So there we can see a number of concise operators that we can use to more efficiently and with less keystrokes for us produce similar results. That's the end of this chapter and in our next chapter we’re going to look at some control structures and see how we can put these variables and operators into use and build our own complex php scripts.

Tutorial Information

Course: PHP
Author: Joshua Mostafa
SKU: 33332
ISBN: 1889347787
Release Date: 2002-03-26
Duration: 9.5 hrs / 92 lessons
Work Files: Yes
Captions: For Online University members only
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 81,350 Video Tutorials (20,800 free)
  • Video Available as Flash or QuickTime
  • Over 782 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available