I will call you back again to another video lecture in PHP.
And in this video lecture, let's go ahead and look at functions in PHP.
All right.
So we're going to look at functions in PHP.
And then we're going to understand what function does and how to use functions in our programs.
So functions are basically a container that we put a piece of information which can perform a specific
task.
So if I want to perform a specific task and you just want to put that inside a container and it can
actually use that container, and it can actually also reuse the container as many times as possible.
You want.
Let me go ahead and start by showing you an example.
Let me go ahead and say echo.
Welcome to pee pee.
All right.
And I've gone ahead and, uh, set these.
So if we go ahead and refresh this, we have.
Welcome to pee pee.
No, this is not inside a function.
I can go ahead and go right in here and, uh, create a function and, uh, this ahead and start.
And we're going to put that we're going to be inside a function and I will see how to use a function.
Now let me go ahead and give that function a name.
Because whenever you create a function, all your functions must have a name so that you can be able
to call that function.
All right.
So let's go ahead and uh say I'll go ahead and say the name is Hello world.
All right.
So that is Hello world.
And uh anytime qualification always go ahead and uh put open and close parentheses and I'll go ahead
and, uh, Cut off this right in here.
Now, if I save this on a fresh, you can see that nothing happens because this function has nothing
right in there.
So if I should go right inside this place and anything I write inside here will be printed out for me.
Remember I wrote Hello World in the beginning?
If I should go ahead and paste it right in there and I'll go ahead and save this.
Now let's check if this will work or not.
Now you can see it never worked.
All right, so you might be like, I've created a function and I put in Hello World and I put in welcome
to PHP.
And that didn't actually work.
So what makes PHP not work when we are we refresh the page is because we did not call the function.
So whenever you create a function, you must always call that function.
So for that function to work, this function was always be called.
Now let's go ahead and call a function.
So how do you call a function.
You just put in the name of the function and open up parentheses and put a semicolon at the end and
save this.
Now we have called this function.
Let's refresh and check it out.
Welcome to PHP.
That is simple.
Right now what if I want to pass in some information to this function.
And if I want to pass information to the function is called a parameter.
It is inside there.
So what am I going to type right inside here your personal information to this function.
So you need to pass in a parameter.
Now let's go ahead and delete everything.
We just got word a read in yet.
So if I should go ahead and say I want in I want to see.
Welcome to PHP.
But I want PHP not to be right inside there.
But I want that to be giving us an information or as a parameter.
What I want it to do is go ahead and put in a variable, and I'm going to call that to be name.
So that is name of the programming language.
And I'll go right in here and pass in that.
So go right in here and say name.
So I have name I've passed in a parameter name inside this function.
And I'll have to equal out the name.
Welcome to whatever parameter I just pass in there.
So I'll go where we call the function.
And I'll go ahead and pass p h p.
And let's save that.
So refresh this I check it out.
Welcome to PHP.
So now I can go right in here and I can go ahead and say we come to CSS and let's go ahead and save
this and see how we come to CSS.
No, you can actually change that.
And you can actually reuse this function.
So I can use this function as many times as possible.
What I need to do is to call this function multiple times.
So if I take this and I paste this maybe also three times, and if I refresh this, it's going to be
on one straight line.
What I need to do right in here is that I'll go back in here and I'm going to put a break tag right
here.
So save this and refresh and have welcome to CS.
Welcome to CS and welcome to CS.
So you can see I was able to reuse this.
So now I can pass in maybe the first one.
I can say welcome to PHP and welcome to the next song is HTML.
And then the last one is welcome to CS.
So if we refresh this you can see we have welcome to PHP.
Welcome to HTML.
Welcome to CS.
So we are able to reuse this function now.
This is the function we created.
So we can create many functions.
And we can call the functions.
And whenever we call that function it is the key to whatever it is in there.
So you can also pass in parameters into your functions.
So this is a single parameter you can pass in multiple parameters.
Let me go ahead and say this is a I pass in name a comma and put another variable and let the variable
be code.
And then let me say this is a PHP 101.
So welcome to PHP.
Um, and I can say welcome to PHP course 101.
So it's going to be code.
So I pass in code.
So welcome to PHP course 101.
So anytime you put in parameter right in here you have to pass in that.
Go down here and say and this is 101 and let me say the next one is 102.
And uh, the next code is 103.
And the sky has said this.
So go ahead and refresh and check it out.
So go ahead and start this.
Welcome to PHP course 101.
Welcome to HTML course 102.
Welcome to CS course 103.
So you can use this as a maybe somebody's name.
Uh, we can't judge.
Your age is 24.
What comes to your age is 26.
So you can actually do that.
All right.
So now we have this course function.
And you have known that functions can be created multiple times.
So we can have different functions to do different jobs in a program.
And in doing that it is easier for you to be able to, you know, clean your code and makes it easy
to use.
You understand, it helps you to be able to organize the code and be able to have your code troubleshoot.
Anytime you have an issue, you have to always go to the function and check out what the problem is
and fix that instead of writing a bunch of code.
Everything without a function.
So I believe you understand what a function is is just a container that is containers, a piece of information
that is the kids that do a specific job.
So is a container, contain a piece of information that do a specific job, and you can reuse your function
as many times as possible.
And the functions contain such information as of parameters.
So it can put in some parameters and in your head and do the job just the way you want it to do it.
So I hope that is cool.
So go ahead and play around with this.
Check it out and if you have any questions use the question and answer section.
And I'm going to get back to you as soon as possible.
Thank you so much.
And I'm going to see you in the next video lecture.