I will call you back again to another video lecture in PHP.
And in this video lecture we go ahead and look at return statement in PHP.
So let's go ahead and learn about return statement because in the previous lecture we discussed about
functions.
And right now I want us to discuss about something very important in functions.
And that is the return statement okay.
Let's go ahead and create a function.
Ready.
Let me go ahead and say this is a function.
And uh let the function name be cube roots.
All right.
So this is called cube roots.
Now the aim of this function I created is for us to calculate cube roots.
So let me go ahead and say equal to what's y to what's it like to.
And then we go ahead and call the function.
And this is cube root.
Then let's go ahead and check this out.
So that is eight its number.
Now, I want us to use a return statement here.
How can we be able to use a return statement here?
So it's very important to learn about that.
All right.
So now I want to remove whatever I have right in here.
So I want to see how to use a return statement in PHP.
And here I'll go right here I'll remove this door I'm going to call that back.
What I want us to take this as a as one step at a time.
Now I want to create something so that once you add such a number, would that be two, three, four,
five, six times?
How many times you want that to be done just inside a number and to give it a culprit of that number?
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
be equal to num.
And let's say num is multiply another variable of norm and multiply another variable of known.
Right.
So press semicolon at the end.
Now we're going to pass this into this function and that is going to be known.
So now we pass this right in there.
So we need to enter a return statement so that when we call this function, any number that is being
inserted right in there is going to give us, we're going to get the cube root of that number.
Now let's go right in here.
So come over here and let us say return.
So I've added a return statement at the end of at the beginning of this.
Not at the end.
At the beginning you can see we're trying to return the cube root that is number.
Multiply the number.
Multiply number.
So that is non multiply unknown multiply unknown.
So whatever number you insert into multiply that three times.
And then we go right in here and call that number.
So let's go ahead and uh call the function.
So A and C echo and their cube root.
So we're trying to call the function right now.
Then go ahead and press semicolon.
Now any number.
I insert it here.
Let me go ahead and say I insert three is going to return the cube root of three.
So go ahead and refresh this and let's check it out.
So you can be able to see we have 27.
So you can see that error statement actually return the cube root.
Now what happens right in here is that any time we use a return statement we are telling PHP that whatever
that is in that function should be returned.
So anything that we write after the return statement, we must be returned.
Let's go ahead and say done here I put in echo.
Hello.
Hello world.
And let's go ahead and try to run this code and check it out.
So you can see I'm trying to run this code and I'm getting only 27 because in PHP, once you use the
word return you often in PHP that everything is done if you've broken out of the code.
So nothing again is going to be run on a ten.
Now, if I should go over here and, uh, cut this, then Let me go and put this right before the return
statement.
Now let's save this again and refresh this.
Hello, world.
Let's go ahead and put a brick dog in here.
Going to save this and refresh.
So you can see I have Hello World.
And below is 27.
So once he is in the world return you actually changed PHP that it should execute whatever you have
in the code that is before the return statement.
I hope that is cool.
So if you add anything after the return statement that will never be executed.
You understand.
So this is an introductory part to return statement in PHP.
Go ahead and practice that you can be able to do so much more with that.
And it's going to be very important.
And it really plays a very vital role in PHP.
Alright.
So why not practice with that and uh, check out more or return statement and if you have any questions
please 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.