Absolute Basics / More Complex Operators pt. 1
Subtitles of the Movie
In this movie, we’re going to look at some more complex operators. Let’s take our num variables that we used in the last set of examples and we’re going to first of all set the value of num to 6. Now if we wanted to increase the value of num by a certain number then we would have to say something like num is set to num plus 3 and if we carry out an echo statement there to check it, the answer of course would be 9. However when we’re programming a lot, we find that it takes a great deal of time to type out the variable name twice and it also reduces the efficiency of our code. So there is a quick way to do that in php, instead of typing out this whole statement, there’s a special combined operator represented like this, plus and then the 'is set to' operator. Let’s take a look at what that looks like. So we’ll save that and then we’ll check it in the browser. Shows us the number 9, now that tells us that this statement takes the value of num, adds 3 to it and then sets the variable num to the result of that addition. Other operators have their similar more complex equivalents such as the minus operator, if we test that. We’ll see that, that gives us a number 3 and similarly for multiplication and division. So that provides us with a quick way of adding or subtracting or multiplying or dividing to any number and returning the value as the new value for the variable. Now for use in string variables, we can use another operator and that is our concatenation operator, a dot you learned in the last chapter followed by the ‘set to’ operator without a space and that will add a new string to our variable and return the result as the new value for the variable. So you try that out and save that and then check that in the browser, we see that the all three characters have been added to the original value of text a word or two. So we can see that this kind of combined concatenation operator works in a similar way to the numeric ones.
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
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 