1 00:00:00 --> 00:00:03 Welcome to a basic tutorial on PHP variables. 2 00:00:04 --> 00:00:06 Let me quickly go through a few things first. 3 00:00:07 --> 00:00:13 PHP variables are very easy to use; I'm sure you'll understand them straight away. 4 00:00:14 --> 00:00:17 You don't need to declare them and they're quite easy to write. 5 00:00:18 --> 00:00:22 You can add a value to a variable half way through the script. 6 00:00:23 --> 00:00:27 Also, they automatically convert to the data type you require. 7 00:00:28 --> 00:00:35 So there's no need to declare them in a different way each time, or create a value for them each time. 8 00:00:36 --> 00:00:40 So, for example, let's create our PHP tags here and our content goes in between. 9 00:00:41 --> 00:00:47 Okay. Now we start with the dollar sign and then we have our variable name. 10 00:00:48 --> 00:00:52 Please note that you can't start with a "number". So I can't start with a '1'. 11 00:00:53 --> 00:00:56 What I can start with is an "underscore" or a "letter". 12 00:00:57 --> 00:01:05 No other special characters are allowed except underscores, letters and numbers, as long as it doesn't start with a number. 13 00:01:06 --> 00:01:08 So that would be perfectly acceptable here. 14 00:01:09 --> 00:01:20 Okay, so I'll create a variable called "name" and that's going to be equal to a string value contained within double quotes, just like we used for the "echo" function. 15 00:01:21 --> 00:01:22 'My name is Alex'. 16 00:01:23 --> 00:01:32 On the next line, we're going to create another variable using a dollar sign, called 'age'. That's going to be equal to '19', without double quotes. 17 00:01:33 --> 00:01:35 Now the reason for this is that this is an integer. 18 00:01:36 --> 00:01:42 You can use it for decimal values as well. So, this could be '19.5' or nineteen and a half. 19 00:01:43 --> 00:01:47 That would also automatically convert this into a decimal. 20 00:01:48 --> 00:01:56 However, at the moment it's just an integer. That's how I want it - the variable 'name' is a string and the variable 'age' is an integer. 21 00:01:57 --> 00:01:59 So, let's try echoing these out. 22 00:02:00 --> 00:02:05 What we need is "echo" and the variable name, not forgetting your line terminator. 23 00:02:06 --> 00:02:10 Okay, let's find our file named "variables". 24 00:02:11 --> 00:02:15 Okay, "Alex" has been echoed out, just like I've said here, "echo name". 25 00:02:16 --> 00:02:18 Let's try and echo out my age now. 26 00:02:19 --> 00:02:23 It's just an integer variable and that's been echoed out here. 27 00:02:24 --> 00:02:29 Okay so, the thing with variables is that they're very easy to concatenate into a string. 28 00:02:30 --> 00:02:36 In fact, probably, concatenation is the wrong word – they're very easy to include inside your string. 29 00:02:37 --> 00:02:45 If you don't know what concatenation is, it just means to join two things together or to join two strings together in a line. 30 00:02:46 --> 00:02:55 So, an example of concatenation would be, let's see, 'concat' and then I could say, '.' and then 'ination'. 31 00:02:56 --> 00:02:58 Now, this would echo out 'concatination'. 32 00:02:59 --> 00:03:02 Let's try this. Okay? 33 00:03:03 --> 00:03:13 But there is a completely different tutorial on that. So, what I'll say is, for now, you don't need to include this as one of your variables when you're echoing it out. 34 00:03:14 --> 00:03:17 If you can't follow this, don't worry. This is very very simple. 35 00:03:18 --> 00:03:23 I'll say "My name is" name "and my age is" and put my age down. 36 00:03:24 --> 00:03:31 Now, it's all in one string, all in one echo, and we've just got 'My name is' – plain text. 37 00:03:32 --> 00:03:39 Variable is called. This is put here. And then when age is called, the value for age is put here. 38 00:03:40 --> 00:03:47 So, we can refresh that and you can see that "My name is Alex". That's our variable. "and my age is 19" and that's our variable. 39 00:03:48 --> 00:03:51 So they're really easy to put into strings. 40 00:03:52 --> 00:03:55 Okay, this is all you really need to know about variables. 41 00:03:56 --> 00:04:05 There are other types of variables, like boolean, decimal – which I've shown you, for example like '19.5'. 42 00:04:06 --> 00:04:09 You would declare them in the same way, with a dollar sign. 43 00:04:10 --> 00:04:18 So practice this and you can come back and learn some more advanced functionality later on, when I'm going through some other projects. 44 00:04:19 --> 00:04:24 Thanks for watching! This is Joshua Mathew dubbing for the Spoken Tutorial project. (Script contributed by Bhavini Pant).