Username: 
Password: 
PHP Tutorials

Absolute Basics / More Complex Operators pt. 1

Subtitles of the Movie

[00:00:00.0] In this movie, we’re going to look at some more complex operators. [00:00:06.0] 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. [00:00:20.0] 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 [00:00:49.0] and if we carry out an echo statement there to check it, the answer of course would be 9. [00:00:57.0] 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 [00:01:13.0] 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 [00:01:30.0] represented like this, plus and then the 'is set to' operator. Let’s take a look at what that looks like. [00:01:51.0] 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, [00:02:14.0] 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 [00:02:33.0] the minus operator, if we test that. We’ll see that, that gives us a number 3 and similarly for multiplication and division. [00:02:55.0] So that provides us with a quick way of adding or subtracting or multiplying or dividing to any number and returning the value [00:03:10.0] 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 [00:03:39.0] 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 [00:04:00.0] as the new value for the variable. So you try that out and save that and then check that in the browser, [00:04:20.0] we see that the all three characters have been added to the original value of text a word or two. [00:04:32.0] So we can see that this kind of combined concatenation operator works in a similar way to the numeric ones. [00:04:44.0]

Tutorial Information

Title: 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
  • 70,000 Video Tutorials (14,250 free)
  • Video Available as Flash or QuickTime
  • Over 650 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available