In this lesson, we're going to introduce you to variables in PHP. Variables are very similar as they are in FileMaker and PHP but there are some differences and we'll go over those. Before we get started though it's a great opportunity to show you something that will really help you during your PHP coding projects. And that is, if you to the website and go to PHP.NET you will find a great resource on PHP code. This is the PHP documentation that's searchable, it has user notes where people put comments, immensely invaluable. And you can pretty much look up every function and every topic related to PHP and get to an answer very quickly. Ironically I happen to be up on a page where it talks about variables and the different types. So right here you can see the different types of variables that are available in PHP. But you don't need to concern yourself too much with that. Variables just like in FileMaker are auto typed. So in other words when you use variables it kind of figures out whether it needs to be an integer or text or a Boolean and you don't have to worry about setting the type as in other programming languages. We'll start by opening up our 0202.php file. Here we start again with basic HTML, don't have any PHP yet. And we'll start by assigning values to our first variable. When you use variables in PHP they need to start off with a dollar sign. That tells the processor this is a variable it's memory in storage and we're going to assign a value to it. After the dollar sign you can either start with a letter or an underscore but no numbers and you can't have spaces in variable names either. We'll say this variable's going to be the first name and I'm going to assign it to the value VTC. Remember to end with a semi-colon. Now we have another variable last name and it's going to have the value training. So I have two variables and just like in FileMaker you can concatenate variables. So for instance I could say that the whole name or full name I'll call that is equal to the first name and in FileMaker you'd use an ampersand but in PHP you would use the period to concatenate two pieces of text. First name and space and then last name. Now I can actually output this variable, the full name down below here in our HTML. And again we'll concatenate down there too. And let's look at our output. Hello I'm VTC Training and yes doing quite well. So continue on with a couple of things before we're done working with variables. You can assign all different types of data to a variable, pretty much anything that's usable in PHP can be assigned to a variable. So for instance you could have a, a numbers, here's a number. You could have floating point numbers you know with, with decimal points, negative numbers. You can have objects, you can have arrays and there's, there's different types in PHP. And as far as type goes it's very smart. It knows what type to kind of make things out. So for instance if you concatenated the first name is equal to VTC and.the number five. It's actually going to convert that five to text and append it to VTC because it's knows that's what you want to do. Whereas you said that the age is equal to VTC plus five, it's going to change VTC to a numeric value which would be a value of zero. So you would end up with five. So it auto types, you can concatenate text and strings and assign them to variables. Lots of different things you can do with variables in PHP and you'll be using them a lot. Before you go, know this. Variables are case sensitive. So the variable number is not equal to number,. Okay. We're ready to move on.
| Course: | FileMaker and PHP Foundations |
| Author: | Lance Hallberg |
| SKU: | 34393 |
| ISBN: | 978-1-61866-077-0 |
| Release Date: | 2012-12-07 |
| Duration: | 7.5 hrs / 97 lessons |
| Work Files: |
Yes |
| Captions: | No |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |