WEBVTT

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

00:03.740 --> 00:11.360
And in this video lecture we go ahead and look at return statement in PHP.

00:18.110 --> 00:24.200
So let's go ahead and learn about return statement because in the previous lecture we discussed about

00:24.200 --> 00:24.950
functions.

00:24.950 --> 00:29.180
And right now I want us to discuss about something very important in functions.

00:29.180 --> 00:32.570
And that is the return statement okay.

00:32.570 --> 00:33.800
Let's go ahead and create a function.

00:33.800 --> 00:34.280
Ready.

00:34.310 --> 00:36.350
Let me go ahead and say this is a function.

00:36.350 --> 00:41.810
And uh let the function name be cube roots.

00:42.020 --> 00:42.440
All right.

00:42.470 --> 00:44.240
So this is called cube roots.

00:44.420 --> 00:49.970
Now the aim of this function I created is for us to calculate cube roots.

00:50.060 --> 00:56.900
So let me go ahead and say equal to what's y to what's it like to.

00:56.930 --> 01:01.100
And then we go ahead and call the function.

01:02.090 --> 01:04.190
And this is cube root.

01:04.490 --> 01:07.820
Then let's go ahead and check this out.

01:08.150 --> 01:10.160
So that is eight its number.

01:10.190 --> 01:14.720
Now, I want us to use a return statement here.

01:14.720 --> 01:17.300
How can we be able to use a return statement here?

01:17.690 --> 01:20.120
So it's very important to learn about that.

01:20.300 --> 01:20.840
All right.

01:20.840 --> 01:25.430
So now I want to remove whatever I have right in here.

01:25.460 --> 01:29.540
So I want to see how to use a return statement in PHP.

01:29.720 --> 01:35.090
And here I'll go right here I'll remove this door I'm going to call that back.

01:35.120 --> 01:38.810
What I want us to take this as a as one step at a time.

01:38.810 --> 01:46.010
Now I want to create something so that once you add such a number, would that be two, three, four,

01:46.010 --> 01:47.120
five, six times?

01:47.150 --> 01:52.370
How many times you want that to be done just inside a number and to give it a culprit of that number?

01:52.370 --> 01:59.900
Now what I'm going to do is go right in here and let's create a variable and let the name of the variable

01:59.930 --> 02:02.870
be equal to num.

02:02.870 --> 02:13.610
And let's say num is multiply another variable of norm and multiply another variable of known.

02:14.690 --> 02:15.140
Right.

02:15.170 --> 02:16.940
So press semicolon at the end.

02:16.970 --> 02:25.100
Now we're going to pass this into this function and that is going to be known.

02:25.100 --> 02:27.410
So now we pass this right in there.

02:27.410 --> 02:34.160
So we need to enter a return statement so that when we call this function, any number that is being

02:34.190 --> 02:39.320
inserted right in there is going to give us, we're going to get the cube root of that number.

02:39.350 --> 02:41.060
Now let's go right in here.

02:41.060 --> 02:45.320
So come over here and let us say return.

02:45.320 --> 02:49.940
So I've added a return statement at the end of at the beginning of this.

02:49.940 --> 02:50.840
Not at the end.

02:50.870 --> 02:55.220
At the beginning you can see we're trying to return the cube root that is number.

02:55.220 --> 02:56.840
Multiply the number.

02:56.870 --> 02:58.430
Multiply number.

02:58.430 --> 03:01.670
So that is non multiply unknown multiply unknown.

03:01.670 --> 03:05.480
So whatever number you insert into multiply that three times.

03:05.480 --> 03:09.260
And then we go right in here and call that number.

03:09.260 --> 03:14.630
So let's go ahead and uh call the function.

03:14.630 --> 03:20.900
So A and C echo and their cube root.

03:21.080 --> 03:24.350
So we're trying to call the function right now.

03:24.380 --> 03:26.390
Then go ahead and press semicolon.

03:26.420 --> 03:27.510
Now any number.

03:27.510 --> 03:28.680
I insert it here.

03:28.710 --> 03:33.210
Let me go ahead and say I insert three is going to return the cube root of three.

03:33.210 --> 03:35.820
So go ahead and refresh this and let's check it out.

03:35.820 --> 03:38.970
So you can be able to see we have 27.

03:38.970 --> 03:43.830
So you can see that error statement actually return the cube root.

03:43.860 --> 03:52.680
Now what happens right in here is that any time we use a return statement we are telling PHP that whatever

03:52.680 --> 03:55.320
that is in that function should be returned.

03:55.320 --> 04:00.090
So anything that we write after the return statement, we must be returned.

04:00.120 --> 04:03.960
Let's go ahead and say done here I put in echo.

04:03.990 --> 04:04.860
Hello.

04:07.470 --> 04:08.400
Hello world.

04:08.490 --> 04:12.210
And let's go ahead and try to run this code and check it out.

04:12.210 --> 04:19.470
So you can see I'm trying to run this code and I'm getting only 27 because in PHP, once you use the

04:19.470 --> 04:26.700
word return you often in PHP that everything is done if you've broken out of the code.

04:26.700 --> 04:29.760
So nothing again is going to be run on a ten.

04:29.790 --> 04:38.550
Now, if I should go over here and, uh, cut this, then Let me go and put this right before the return

04:38.550 --> 04:39.210
statement.

04:39.240 --> 04:42.360
Now let's save this again and refresh this.

04:42.390 --> 04:43.170
Hello, world.

04:43.200 --> 04:47.610
Let's go ahead and put a brick dog in here.

04:47.640 --> 04:49.740
Going to save this and refresh.

04:49.740 --> 04:52.020
So you can see I have Hello World.

04:52.020 --> 04:53.760
And below is 27.

04:53.760 --> 05:00.960
So once he is in the world return you actually changed PHP that it should execute whatever you have

05:00.960 --> 05:04.860
in the code that is before the return statement.

05:05.760 --> 05:06.750
I hope that is cool.

05:06.750 --> 05:11.250
So if you add anything after the return statement that will never be executed.

05:13.350 --> 05:13.980
You understand.

05:13.980 --> 05:18.450
So this is an introductory part to return statement in PHP.

05:18.630 --> 05:22.890
Go ahead and practice that you can be able to do so much more with that.

05:22.890 --> 05:24.810
And it's going to be very important.

05:24.810 --> 05:28.410
And it really plays a very vital role in PHP.

05:28.800 --> 05:29.220
Alright.

05:29.220 --> 05:35.640
So why not practice with that and uh, check out more or return statement and if you have any questions

05:35.640 --> 05:38.070
please use the question and answer section.

05:38.070 --> 05:40.740
And I'm going to get back to you as soon as possible.

05:40.770 --> 05:41.760
Thank you so much.

05:41.760 --> 05:44.760
And I'm going to see you in the next video lecture.
