WEBVTT

00:00.560 --> 00:03.770
I will call you back again to another video lecture in PHP.

00:03.770 --> 00:09.860
And in this video lecture, let's go ahead and look at functions in PHP.

00:16.880 --> 00:17.390
All right.

00:17.390 --> 00:19.970
So we're going to look at functions in PHP.

00:19.970 --> 00:26.180
And then we're going to understand what function does and how to use functions in our programs.

00:26.180 --> 00:35.060
So functions are basically a container that we put a piece of information which can perform a specific

00:35.060 --> 00:35.900
task.

00:35.900 --> 00:43.310
So if I want to perform a specific task and you just want to put that inside a container and it can

00:43.310 --> 00:49.190
actually use that container, and it can actually also reuse the container as many times as possible.

00:49.190 --> 00:49.970
You want.

00:50.180 --> 00:55.760
Let me go ahead and start by showing you an example.

00:55.790 --> 00:58.040
Let me go ahead and say echo.

00:59.450 --> 01:02.200
Welcome to pee pee.

01:02.710 --> 01:03.040
All right.

01:03.070 --> 01:05.740
And I've gone ahead and, uh, set these.

01:05.740 --> 01:08.710
So if we go ahead and refresh this, we have.

01:08.740 --> 01:09.970
Welcome to pee pee.

01:11.020 --> 01:14.080
No, this is not inside a function.

01:14.500 --> 01:22.990
I can go ahead and go right in here and, uh, create a function and, uh, this ahead and start.

01:23.050 --> 01:28.990
And we're going to put that we're going to be inside a function and I will see how to use a function.

01:28.990 --> 01:32.410
Now let me go ahead and give that function a name.

01:32.410 --> 01:37.630
Because whenever you create a function, all your functions must have a name so that you can be able

01:37.630 --> 01:39.520
to call that function.

01:39.820 --> 01:40.390
All right.

01:40.390 --> 01:46.270
So let's go ahead and uh say I'll go ahead and say the name is Hello world.

01:48.460 --> 01:48.940
All right.

01:48.940 --> 01:51.190
So that is Hello world.

01:51.190 --> 01:58.900
And uh anytime qualification always go ahead and uh put open and close parentheses and I'll go ahead

01:58.900 --> 02:01.830
and, uh, Cut off this right in here.

02:02.520 --> 02:11.010
Now, if I save this on a fresh, you can see that nothing happens because this function has nothing

02:11.010 --> 02:11.910
right in there.

02:11.910 --> 02:18.840
So if I should go right inside this place and anything I write inside here will be printed out for me.

02:19.380 --> 02:21.810
Remember I wrote Hello World in the beginning?

02:21.810 --> 02:26.100
If I should go ahead and paste it right in there and I'll go ahead and save this.

02:26.100 --> 02:29.010
Now let's check if this will work or not.

02:29.700 --> 02:32.970
Now you can see it never worked.

02:34.620 --> 02:42.480
All right, so you might be like, I've created a function and I put in Hello World and I put in welcome

02:42.480 --> 02:43.290
to PHP.

02:43.290 --> 02:45.300
And that didn't actually work.

02:45.300 --> 02:53.490
So what makes PHP not work when we are we refresh the page is because we did not call the function.

02:53.490 --> 02:57.720
So whenever you create a function, you must always call that function.

02:57.720 --> 03:01.520
So for that function to work, this function was always be called.

03:02.420 --> 03:04.700
Now let's go ahead and call a function.

03:04.700 --> 03:06.320
So how do you call a function.

03:06.320 --> 03:13.550
You just put in the name of the function and open up parentheses and put a semicolon at the end and

03:13.550 --> 03:14.240
save this.

03:14.240 --> 03:16.190
Now we have called this function.

03:16.370 --> 03:18.320
Let's refresh and check it out.

03:18.350 --> 03:20.330
Welcome to PHP.

03:22.010 --> 03:22.640
That is simple.

03:22.640 --> 03:30.050
Right now what if I want to pass in some information to this function.

03:30.170 --> 03:34.700
And if I want to pass information to the function is called a parameter.

03:34.700 --> 03:36.410
It is inside there.

03:36.410 --> 03:40.310
So what am I going to type right inside here your personal information to this function.

03:40.310 --> 03:42.680
So you need to pass in a parameter.

03:42.710 --> 03:45.050
Now let's go ahead and delete everything.

03:45.050 --> 03:47.420
We just got word a read in yet.

03:47.690 --> 03:54.140
So if I should go ahead and say I want in I want to see.

03:54.170 --> 03:55.460
Welcome to PHP.

03:55.490 --> 03:59.450
But I want PHP not to be right inside there.

03:59.480 --> 04:05.230
But I want that to be giving us an information or as a parameter.

04:05.230 --> 04:12.910
What I want it to do is go ahead and put in a variable, and I'm going to call that to be name.

04:12.910 --> 04:16.210
So that is name of the programming language.

04:16.210 --> 04:21.550
And I'll go right in here and pass in that.

04:21.550 --> 04:25.240
So go right in here and say name.

04:26.230 --> 04:29.860
So I have name I've passed in a parameter name inside this function.

04:29.860 --> 04:32.650
And I'll have to equal out the name.

04:32.650 --> 04:36.040
Welcome to whatever parameter I just pass in there.

04:36.040 --> 04:38.530
So I'll go where we call the function.

04:38.530 --> 04:40.930
And I'll go ahead and pass p h p.

04:40.930 --> 04:42.520
And let's save that.

04:42.520 --> 04:44.560
So refresh this I check it out.

04:44.590 --> 04:46.090
Welcome to PHP.

04:47.500 --> 04:55.150
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

04:55.150 --> 04:59.380
this and see how we come to CSS.

05:01.110 --> 05:04.020
No, you can actually change that.

05:04.020 --> 05:06.600
And you can actually reuse this function.

05:06.600 --> 05:09.840
So I can use this function as many times as possible.

05:09.870 --> 05:14.280
What I need to do is to call this function multiple times.

05:14.280 --> 05:21.330
So if I take this and I paste this maybe also three times, and if I refresh this, it's going to be

05:21.360 --> 05:22.350
on one straight line.

05:22.380 --> 05:28.770
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

05:28.770 --> 05:29.190
here.

05:29.190 --> 05:33.030
So save this and refresh and have welcome to CS.

05:33.060 --> 05:36.000
Welcome to CS and welcome to CS.

05:36.360 --> 05:39.300
So you can see I was able to reuse this.

05:39.300 --> 05:41.880
So now I can pass in maybe the first one.

05:41.910 --> 05:49.950
I can say welcome to PHP and welcome to the next song is HTML.

05:50.040 --> 05:52.530
And then the last one is welcome to CS.

05:52.530 --> 05:55.860
So if we refresh this you can see we have welcome to PHP.

05:55.950 --> 05:57.300
Welcome to HTML.

05:57.330 --> 05:58.920
Welcome to CS.

05:58.940 --> 06:02.180
So we are able to reuse this function now.

06:02.210 --> 06:03.770
This is the function we created.

06:03.770 --> 06:05.720
So we can create many functions.

06:05.750 --> 06:07.130
And we can call the functions.

06:07.130 --> 06:10.970
And whenever we call that function it is the key to whatever it is in there.

06:10.970 --> 06:14.390
So you can also pass in parameters into your functions.

06:15.590 --> 06:20.630
So this is a single parameter you can pass in multiple parameters.

06:20.660 --> 06:28.610
Let me go ahead and say this is a I pass in name a comma and put another variable and let the variable

06:28.640 --> 06:29.840
be code.

06:29.840 --> 06:33.110
And then let me say this is a PHP 101.

06:33.110 --> 06:34.790
So welcome to PHP.

06:36.230 --> 06:43.310
Um, and I can say welcome to PHP course 101.

06:43.310 --> 06:47.510
So it's going to be code.

06:47.510 --> 06:48.860
So I pass in code.

06:48.860 --> 06:50.660
So welcome to PHP course 101.

06:50.660 --> 06:55.100
So anytime you put in parameter right in here you have to pass in that.

06:55.130 --> 07:03.310
Go down here and say and this is 101 and let me say the next one is 102.

07:03.340 --> 07:07.630
And uh, the next code is 103.

07:07.630 --> 07:09.340
And the sky has said this.

07:09.340 --> 07:11.950
So go ahead and refresh and check it out.

07:12.730 --> 07:14.110
So go ahead and start this.

07:14.140 --> 07:16.300
Welcome to PHP course 101.

07:16.300 --> 07:18.790
Welcome to HTML course 102.

07:18.820 --> 07:21.370
Welcome to CS course 103.

07:21.790 --> 07:24.760
So you can use this as a maybe somebody's name.

07:24.790 --> 07:26.050
Uh, we can't judge.

07:26.080 --> 07:28.090
Your age is 24.

07:28.120 --> 07:32.440
What comes to your age is 26.

07:33.100 --> 07:34.900
So you can actually do that.

07:35.050 --> 07:35.560
All right.

07:35.560 --> 07:38.980
So now we have this course function.

07:38.980 --> 07:43.360
And you have known that functions can be created multiple times.

07:43.360 --> 07:47.860
So we can have different functions to do different jobs in a program.

07:47.860 --> 07:54.970
And in doing that it is easier for you to be able to, you know, clean your code and makes it easy

07:54.970 --> 07:55.870
to use.

07:56.080 --> 08:03.720
You understand, it helps you to be able to organize the code and be able to have your code troubleshoot.

08:03.720 --> 08:09.360
Anytime you have an issue, you have to always go to the function and check out what the problem is

08:09.390 --> 08:12.390
and fix that instead of writing a bunch of code.

08:12.420 --> 08:14.070
Everything without a function.

08:14.070 --> 08:20.580
So I believe you understand what a function is is just a container that is containers, a piece of information

08:20.580 --> 08:24.360
that is the kids that do a specific job.

08:24.540 --> 08:31.260
So is a container, contain a piece of information that do a specific job, and you can reuse your function

08:31.290 --> 08:33.330
as many times as possible.

08:33.960 --> 08:37.920
And the functions contain such information as of parameters.

08:37.920 --> 08:45.030
So it can put in some parameters and in your head and do the job just the way you want it to do it.

08:45.060 --> 08:46.440
So I hope that is cool.

08:46.440 --> 08:48.120
So go ahead and play around with this.

08:48.150 --> 08:52.080
Check it out and if you have any questions use the question and answer section.

08:52.080 --> 08:54.570
And I'm going to get back to you as soon as possible.

08:54.600 --> 08:55.620
Thank you so much.

08:55.620 --> 08:58.770
And I'm going to see you in the next video lecture.
