Hello, in this video, I am going to cover functions. So a function is essentially a way of wrapping up some code that allows you to corely at a later date. So let me just create a simple function of a function. And I'll call it Hello. So this is the general structure, you put the keyword function to say that it's going to be a function, you put the function name, this is what will be used to initiate it. And these are required.
We'll cover this over the next couple of videos. This allows you to basically pass you know information into the function, but that's for a separate video. And the started end curly brace is similar to a loop or a control structure, such as a if statement where all the code goes inside of it. So if I just run this, you'll see nothing happened. So if I put in echo And I'm going to do a break rule. Do we all do it.
There's no real significance to this, but want to demonstrate something. So if I run that now, still nothing is because unless we actually call the function, you won't actually get run. To call it you just put the name of the function, open closed brackets, run it, there we go. 12345. But the beauty of this instead of just writing this code, if we want to execute, you know, the code inside of that function again, all you do is do this. Copy and paste it.
As you can see, we've just four extra lines. I these four extra lines are there to print out the five echo command again. So 20 lines was reduced to four. So that's the beauty of using a function. Also, you might think you could just use a loop. And yes, you could.
But you might not want to use the function multiple times, one after another, you might want to use in different parts of your website. Therefore functions are a great use case for this. And yeah, you can have code in between as well. So feel free to experiment you can have as many functions as you want. They are really useful and I'll be covering more function features over the next few videos.