PHP-and-MySQL/C2/Variables-in-PHP/English-timed

From Script | Spoken-Tutorial
Jump to: navigation, search
Time Narration
00:00 Welcome to a basic tutorial on PHP variables.
00:04 Let me quickly go through a few things first.
00:07 PHP variables are very easy to use; I'm sure you'll understand them straight away.
00:14 You don't need to declare them and they're quite easy to write.
00:18 You can add a value to a variable half way through the script.
00:23 Also, they automatically convert to the data type you require.
00:28 So, there's no need to declare them in a different way each time or create a value for them each time.
00:36 So, for example, let's create our PHP tags here and our content goes in between.
00:41 Okay. Now we start with the dollar sign ($) and then we have our variable name.
00:48 Please note that you can't start with a number. So, I can't start with a '1'.
00:53 What I can start with is: an underscore or a letter.
00:57 No other special characters are allowed except underscores, letters and numbers as long as it doesn't start with a number.
01:06 So, that would be perfectly acceptable here.
01:09 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.
01:21 My name is "Alex".
01:23 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.
01:33 Now, the reason for this is that is an integer.
01:36 You can use it for decimal values as well. So, this could be '19.5' or nineteen and a half.
01:43 That would also automatically convert this into a decimal.
01:48 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.
01:57 So, let's try echoing these out.
02:00 What we need is "echo" and the variable name, not forgetting your line terminator.
02:06 Okay, let's find our file named "variables".
02:11 Okay, "Alex" has been echoed out, just like I've said here, "echo name".
02:16 Let's try and echo out my age now.
02:19 It's just an integer variable and that's been echoed out here.
02:24 Okay. So, the thing with variables is that they are very easy to concatenate into a string.
02:30 In fact, probably, concatenation is a wrong word – they're very easy to include inside your string.
02:37 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.
02:46 So, an example of concatenation would be, let's see, 'concat' and then I could say, '.' and then 'ination'.
02:56 Now, this would echo out 'concatination'.
02:59 Let's try this. Okay?
03:03 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 this out.
03:14 If you can't follow this, don't worry. This is very very simple.
03:18 I'll say "My name is" $name "and my age is" and put my age down.
03:24 Now, it's all in one string, all in one echo and we've just got 'My name is' – plain text.
03:32 Variable is called. This is put here. And then when age is called, the value for age is put here.
03:40 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.
03:48 So, they're really easy to put into strings.
03:52 Okay, this is all you really need to know about variables.
03:56 There are other types of variables like boolean, decimal – which I've shown you, for example like '19.5'.
04:06 You would declare them in the same way, with a dollar sign.
04:10 So, practice this and you can come back and learn some more advanced functionality later on when I'm going through some other projects.
04:19 Thanks for watching! This is Joshua Mathew dubbing for the Spoken Tutorial project. (Script contributed by Bhavini Pant).

Contributors and Content Editors

Minal, Pratik kamble, Sandhya.np14