Lecture 30: Custom Functions
While PHP has a massive library of built-in functions you have at your disposal, sometimes you need to build your own functions — for both small and large tasks.
Think of a custom functions as a mini-program that performs an action for you — better yet, think of a custom function as a cute little robot that does a specific task you tell it to do!
Let's look at the basic syntax of a function:
function myCustomFunction() {
// things my custom function will do
// go in here
}
To build your custom function, you need to type function myCustomFunction(). Keep in mind that "myCustomFunction()" can be whatever words you want them to be, but no spaces allowed. Then add opening and closing curly brackets (or curly braces, as some call it). In between the curly brackets is where you define what your function will perform.
There are two important things to know about functions:
There are functions that require "arguments", and;
There are functions that don't require "arguments".
Let's start by building a custom function that does not require an argument.
// Build the function
function hangTen() {
echo "Surf's up! Grab your board!";
}
// Call the function
hangTen();
DOWNLOAD COURSE FILES HERE
http://www.bradhussey.ca/download-php...