PHP Basics / Variable Basics
Subtitles of the Movie
In this lesson, we'll be learning the basics of PHP variables. We'll be learning just enough about variables so that we can use them in subsequent lessons. We'll be learning a lot more about PHP variables later on. Variables in PHP are a lot like variables in FileMaker Pro. Let's open up our FileMaker Pro application and enter script maker from any open file. Create a new temporary script and add the set variables script step. Specify a name for your variable. Notice that FileMaker automatically prepends the name of the variable with a dollar sign. All variable names in FileMaker Pro must begin with at least one dollar sign. In PHP, variable names also begin with a dollar sign. The value of this variable will be the results of the FileMaker let function. The let function in FileMaker allows us to assign multiple values to new variables. We'll say that the variable first is equal to VTC and the variable last is equal to the string training. Our calculated result will be a concatenation or a combining of these two strings. In FileMaker Pro, we can catenate strings with the ampersand. So we'll say the result is first ampersand space ampersand last. click OK and then ok again. And now scroll down to the show customs dialog script step. We'll display the new variable in the dialog box to verify its contents. Under the message field, type the name of your variable. Save your script and run it. Notice we see the concatenation of the two texts, VTC and training. Now let's see how we can do the same variable assignments in PHP. In your text editor, open up a new document with minimal HTML code. We'll create a new PHP code block at the top and assign the values to our two new variables, first and last. Remember to start the variable name with the dollar sign. First is equal to the string VTC. Terminate your statement with semi-colon. Last is equal to the string training. Now we'll concatenate the two together in our variable name. Name is equal to first and I'll stop right here. In PHP, we concatenate strings with the period or the dot, rather than the ampersand sign. Name is equal to first period space period last. Now that we've assigned the value to a variable name, we'll create a new code block in the body of our HTML document. And we'll echo the value of the variable. Refresh this page in your browser and verify that you're getting the concatenated results of your two variables. Notice that using variables in PHP is a lot like using variables in FileMaker Pro. Variable names in PHP must begin with either the underscore or an alpha character. After the first character of the variable name, you can use any combination of an underscore or an alpha or a numeric character. You can not begin variable names in PHP with a number. If you've assigned a numeric value to a variable in PHP, such as total is equal to five, you can increase that value by one or decrease that value by one using an increment or decrement operator. The increment operator is two plus signs. The decrement operator is two minus signs. Let's show how the increment and decrement operators work. We'll say that Y is equal to minus minus total. And then we'll echo Y to the browser. Refresh and we can see that Y is equal to four. What PHP is doing here is decremating the value of total, which is five, by one and then assigning that value to the variable Y. We could put the decrement operators at the end of total. This is very interesting because what PHP will do is first assign the value of total to Y and then decrement it. So Y is actually still going to be five. But total will have decremented down to four. It's important to understand the precedence of this operation so that you know where to use your increment or decrement either at the beginning of the variable or at the end of the variable so that you get predicted results. Oftentimes, unpredicted results occur because we don't understand the precedence of putting the increment or the decrement operator at the beginning of the variable or at the ending of the variable. One more thing to note about PHP variables before we move on and that is that the names are case sensitive. So that the variable Total is not equal to the variable total. This covers the basics of using PHP variables. As you can see, they're very similar to FileMaker Pro variables and should be easy to pick up and to master later on.
Tutorial Information
| Course: | FileMaker 9 & PHP Foundations |
| Author: | Lance Hallberg |
| SKU: | 33786 |
| ISBN: | 1-933736-99-2 |
| Release Date: | 2007-08-22 |
| Duration: | 9.5 hrs / 107 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
United States 