 Hey everybody, this is Brian. Welcome to the 10th LAMP tutorial. Today we're going to be covering functions. Now if you're following along with W3 schools, you'll notice how functions is way down here. We left off at strings. Well, I kind of don't agree with the way they're teaching this. They teach you all these other things and then jump down to functions. But functions, you kind of need to understand these to understand what these things are doing. So we're gonna jump down to functions and then we'll jump back up here and cover all these. Alright, let's crack open trusty Komodo IDE and we are going to write our function. Now what is the format of a function you ask? I'm glad you asked. See how it simply says function, function name, code to be executed. You can call your function from anywhere in there. There's some rules you have to follow. Let's see here. Give the function a name that reflects what the function does. The function name can start with a letter or just underscore but not a number. Notice that not a number. Here's an example. You've got your HTML you're used to, your PHP and a function and then something going on here and see how they're calling that function right name. Well, we're gonna go over this real quick. So what we're gonna say here is function. We're just gonna say test. Now notice the brackets. What we're doing here is making a block of code. This is called a code block. Here is our function and all its glory. Which means when we call test everything within these brackets is going to run. So we're just going to say echo 1, echo 2 and of course echo 3. Why 3 you ask? Well just because we can. Now what we're going to do is call our function. Gotta love comments. Let you know what's going on in the world. Now to call our function simply write it out. There we go. 1, 2, 3. So what happens here? Let's examine this. PHP starts executing. It looks for, you guessed it, PHP tag. Or I should say PHP code block. It gets here. It says this is our function. It's common ignores. It says function test. Well, you would think it would just go in here and start executing. No, because this hasn't been called yet. So it jumps right over here and says okay, what are we doing? We're calling our function. Notice how it has a semicolon at the end. We could very easily take this and plop it up there. See? Same results. It's not for a simplistic sake. Let's throw it back down here and I'm gonna give you another function. Print our name. Function. We'll just call this print name. Notice how we have a dollar sign, meaning we're creating a variable here. This is actually called a parameter, but it's also a variable. So we'll say echo. Actually, let's not do that. Let's just, for a simplistic sake here, let's just say name. That way you can see what's really going on here. We're gonna call our other function. We're gonna say print name. Notice how now the IntelliSense pops up and says it's asking for something here. So what we need is to give it a parameter. Let's actually print out the hard return here so we don't get confused with what's going on. And there we go. One, two, three, and then Brian. So you see what a function is and yes, you can actually make a variable. And let's just say my name. And instead of giving it a wrong string, you can actually pass it a variable. See? Very simple, very easy to understand. A function is just a block of code. For example, here's a block. And then here's a block. And the only time that block of code gets executed is when you call that function name. For example, we're calling test. So it'll execute test. We're calling print name. So I'm sorry, we're calling print name. So it'll execute print name. We're also passing a parameter of my name. But in the block, this is called variable scope here. It's used name, not my name. Let's examine this super quick. We have a variable called my name. We're passing it as a parameter to the function print name, meaning right here. But in this function, we're calling it name. We can call it anything we want. We can call it fuzzy bunny if you're so inclined. As long as it has scope, it will work. All right. This is Brian. Thank you for watching. I hope you found this tutorial educational and entertaining.