Locked lesson.
About this lesson
How to create and use functions in PHP.
Exercise files
Download this lesson’s related exercise files.
Functions.docx59.1 KB Functions - Solution.docx
59.7 KB
Quick reference
Functions
Functions are like programs inside of our program.
When to use
Functions allow us to reuse code.
Instructions
Functions only run if you specifically call them. Otherwise they are ignored by the normal flow of our code.
Functions take this form:
function my_function(){
// do something;
}
To call a function:
my_function();
You can pass parameters into a function when you call it:
my_function("John", "Elder");
Hints & tips
- functions are programs inside your program
- functions only run if you specifically call them
- You can pass parameters into a function when you call it
Lesson notes are only available for subscribers.