Lesson 12 PHP Functions

Learn to define and call PHP functions using the `function` keyword and curly braces. Functions let you wrap repetitive code in one place, return values like booleans or strings, and use those values in conditionals.
Chapters
Hello again, and in this tutorial we are going to be learning about functions. Functions are essential if you are doing a repetitive task over and over. Basically what it is, is you can assign some script to a function and then call a function anywhere in your code, so then it basically runs all that script using a Okay, this is how you make a function. All you have to do is type function, our function name, we'll just call it f, and wrap it up like that. Just like that. Okay. Now inside of our function, we're going to do some stuff. We can do anything. We can do anything we can do outside of it. We can echo, we can die, we can access our MySQL database. We can basically do anything. And we run it by calling f right there. Save our changes. F5, and it'll say F has been run. We can also have a return, which basically returns a variable, which is like a— we can include things like this or like a We say we want to call something with variable type. Yeah, making this confusing. We want to run f using this string. Oops. So basically, this string right here will be assigned this variable. Variable, and then we can use that string anywhere over here, just like that. We can also return, such as return true or return false, or we could return a string. Basically, return would work like this: if f String. This would return a true because we have a true here and there's no reason why it should be false. Therefore, it would run the script inside of if. That is basically all for functions. Thanks for watching. See you next time.










